Home Reactor Operations
Post
Cancel

Reactor Operations

๐Ÿงถ ์ƒ์„ฑ

Create

image https://reactivex.io/

  • Observable ์ƒ์„ฑ

Just

image https://reactivex.io/documentation/operators/just.html

  • ํ•˜๋‚˜์˜ item๋งŒ ๋ฐฉ์ถœ(emit)ํ•˜๋Š” observable ์ƒ์„ฑ

From

image https://reactivex.io/documentation/operators/from.html

  • ๋‹ค์–‘ํ•œ ๊ฐ์ฒด์™€ ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ observable๋กœ ๋ณ€ํ™˜
  • e.g. ๋ฆฌ์ŠคํŠธ๋ฅผ Flux๋กœ ๋ณ€ํ™˜

Empty

image https://reactivex.io/documentation/operators/empty-never-throw.html

  • ๋นˆ observable ์ƒ์„ฑ

Defer

image https://reactivex.io/documentation/operators/defer.html

  • observer๊ฐ€ ๊ตฌ๋…ํ•  ๋•Œ๊นŒ์ง€ observable์„ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ , ๊ฐ observer์— ๋Œ€ํ•ด ์ƒˆ๋กœ์šด observable ์ƒ์„ฑ


๐Ÿ”ฎ ๋ณ€ํ™˜

flatMap

image https://reactivex.io/

๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ

groupBy

image https://reactivex.io/

  • Obsevable์„ ๊ธฐ์ค€์— ๋”ฐ๋ผ ๊ทธ๋ฃน์œผ๋กœ obsevable ๋ฐฉ์ถœ

map

image https://reactivex.io/

๋™๊ธฐ ์ฒ˜๋ฆฌ

์ž…๋ ฅ๊ณผ ๋ฆฌํ„ด ๊ฐ’์€ Mono<T>


๐Ÿ”Š ํ•„ํ„ฐ

distinct

  • ์ค‘๋ณต์„ ์—†์•ค observable ๋ฐ˜ํ™˜

filter

  • ์กฐ๊ฑด์— ๋งŒ์กฑํ•˜๋Š” ํ•ญ๋ชฉ๋งŒ ๋ฐฉ์ถœ

elementAt

image https://reactivex.io/

  • Flux์—์„œ i๋ฒˆ์งธ ์š”์†Œ๋ฅผ Mono๋กœ ๋ฐ˜ํ™˜

ignoreElements

image https://reactivex.io/

  • Observable์˜ ํ•ญ๋ชฉ์„ ๋‚ด๋ณด๋‚ด์ง€ ์•Š๊ณ  ์ข…๋ฃŒ ์•Œ๋ฆผ ๋ฐœ์ƒ
  • Observable์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ข…๋ฃŒํ•  ๋•Œ ์ด์šฉ
  • onNext ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค.

take

image https://reactivex.io/

  • ์•ž์—์„œ n๊ฐœ์˜ ์š”์†Œ ๋ฐฉ์ถœ


๐Ÿงฉ ๊ฒฐํ•ฉ

merge

image https://reactivex.io/

  • ์—ฌ๋Ÿฌ observable์„ ํ•ฉ์ณ์„œ ํ•˜๋‚˜์˜ observable ๋ฐ˜ํ™˜

startWith

image https://reactivex.io/

  • Observable์˜ ํ•ญ๋ชฉ์„ ๋ฐฉ์ถœํ•˜๊ธฐ ์ „์— ์ง€์ •๋œ ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€

zip

image https://reactivex.io/

  • ์—ฌ๋Ÿฌ observable์˜ ๋ฐฉ์ถœ์„ ๊ฒฐํ•ฉํ•˜์—ฌ ํ•˜๋‚˜์˜ observable๋กœ ๋ฐฉ์ถœ


๐Ÿ“ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ

onErrorResume

image https://reactivex.io/

  • error ์‹ ํ˜ธ ์ฒ˜๋ฆฌ

try-catch ๋ฌธ์—์„œ catch์™€ ์œ ์‚ฌ

retry

image https://reactivex.io/

  • error ์‹ ํ˜ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋‹ค์‹œ ์‹คํ–‰


๐ŸŽฎ ์œ ํ‹ธ๋ฆฌํ‹ฐ

delay

  • Observable์—์„œ ๋ฐฉ์ถœ ์‹œ์ ์„ ํŠน์ • ์‹œ๊ฐ„๋งŒํผ ์•ž์œผ๋กœ ์ด๋™

do

image https://reactivex.io/

  • ์›๋ณธ ์‹œํ€€์Šค์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ณ  ์ฒ˜๋ฆฌ ๋กœ์ง ์ถ”๊ฐ€
  • ์ฃผ๋กœ ์‹œํ€€์Šค์˜ ์‹ ํ˜ธ๋ฅผ ์žก์•„์„œ ์‚ฌ์šฉ
  • e.g. doOnNext, doOnComplete, doOnError ๋“ฑ

serialize

image https://reactivex.io/

  • Observable์ด ์ง๋ ฌํ™”๋œ ํ˜ธ์ถœ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๋„๋ก ๊ฐ•์ œ

subscribe

  • Observable ๋ฐฉ์ถœ ๋ฐ ์•Œ๋ฆผ์— ๋”ฐ๋ผ ์ž‘๋™
  • e.g. onNext, onError, onComplete

๊ตฌ๋…ํ•˜์ง€ ์•Š์€ Observable์€ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š๋Š”๋‹ค.

timestamp

image https://reactivex.io/

  • ๊ฐ ํ•ญ๋ชฉ์— ํƒ€์ž„์Šคํƒฌํ”„ ์ถ”๊ฐ€


๐Ÿ”Ž ์กฐ๊ฑด

all

image https://reactivex.io/

  • Observable์ด ๋‚ด๋ณด๋‚ธ ๋ชจ๋“  ํ•ญ๋ชฉ์ด ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š”์ง€ ์—ฌ๋ถ€ ๋ฐ˜ํ™˜

contains

image https://reactivex.io/

  • Observable์ด ํŠน์ • ํ•ญ๋ชฉ์„ ๋ฐฉ์ถœํ•˜๋Š”์ง€ ์—ฌ๋ถ€ ๋ฐ˜ํ™˜

defaultIfEmpty

image https://reactivex.io/

  • Observable์ด ์•„๋ฌด๊ฒƒ๋„ ๋ฐฉ์ถœํ•˜์ง€ ์•Š์„ ๋•Œ ํŠน์ • ํ•ญ๋ชฉ ๋ฐ˜ํ™˜

skipWhile

image https://reactivex.io/

  • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ์•Š์„ ๋•Œ๊นŒ์ง€ ๋ฐฉ์ถœ๋œ ํ•ญ๋ชฉ ๋ฌด์‹œ

takeWhile

image https://reactivex.io/

  • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜์ง€ ์•Š์€ ํ›„ observable์ด ๋‚ด๋ณด๋‚ธ ํ•ญ๋ชฉ ๋ฌด์‹œ


๐Ÿ“ ์ง‘๊ณ„

average

  • ๋’ค์— ์ž๋ฃŒํ˜•์„ ๋ถ™์—ฌ์„œ ์‚ฌ์šฉ
  • ํ‰๊ท ์„ Mono๋กœ ๋ฐ˜ํ™˜

count

  • ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” item์˜ ๊ฐœ์ˆ˜๋ฅผ ์นด์šดํŒ…ํ•˜์—ฌ Mono๋กœ ๋ฐ˜ํ™˜

max

  • ์ตœ๋Œ“๊ฐ’

min

  • ์ตœ์†Ÿ๊ฐ’

sum

  • ํ•ฉ

reduce

image https://reactivex.io/

  • ์‹œํ€€์Šค์˜ ๊ฐ item์— ํ•จ์ˆ˜๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์ ์šฉํ•˜๊ณ  ์ตœ์ข… ๊ฐ’ ๋ฐ˜ํ™˜


This post is licensed under CC BY 4.0 by the author.

Reactive Programming

WebFlux