brunch

You can make anything
by writing

C.S.Lewis

by 으아한구렝 Mar 03. 2018

5. Filtering Operators

operator chaining을 통해 subscriber에게 실제로 전달될 event를 filtering합니다.

이하 'index n'이라고 표시한 것은 zero base index에서 n을 의미합니다.


Ignoring operators

.ignoreElements(): 모든 .next를 무시합니다.

.elementAt(): index n에 해당하는 .next를 제외한 모든 .next를 무시합니다.

.filter(): 조건에 맞는 .next를 제외한 모든 .next를 무시합니다.


Skipping operators

.skip(): index n까지의 .next를 무시합니다. 이후의 모든 .next를 handling합니다.

.skipWhile(): 조건에 맞지 않는 .next가 나타날 때까지 조건에 맞는 .next를 무시합니다. 이후의 모든 .next를 handling합니다.

.skipUntil(): trigger observable이 .next를 emit할 때까지 source observable의 .next를 무시합니다. 이후의 모든 .next를 handling합니다.


Taking operators

.take(): n개의 .next만 handling합니다. 이후의 모든 .next를 무시합니다.

.takeWhile(): 조건에 맞는 .next만 handling합니다.

.takeUntil(): trigger observable이 .next를 emit할 때까지 source observable의 .next를 handling합니다. 이후의 모든 .next를 무시합니다.


Distinct operators

distinctUntilChanged(): 같은 value를 가진 .next가 연속적으로 들어오면 무시합니다. value가 달라질 경우 .next를 handling합니다. value가 Equtable을 conform하고 있지 않는 element의 경우 혹은 equation을 직접 정의하고 싶은 경우엔 argument로 closure를 넘겨줍니다.


Challenges

갑작스럽게 toArray()를 사용해보라고 합니다. toArray()한 후, subscribe하면 .next의 value로 element array를 받을 수 있습니다.

Converts an Observable into another Observable that emits the whole sequence as a single array and then terminates.



의문점 / 공부할 부분

특별한 내용은 없습니다. 술술 읽힙니다.


작가의 이전글 4. Observables and Subjects...
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari