1. distinctUntilChanged

→ 중복값 방지 latest랑 같은게 나오면 무시함

Untitled

example(of: "distinctUntilChanged") {
    Observable.of("A","A","B","B","C","D","E")
        .distinctUntilChanged()
        .subscribe{
            print($0)
        }
        .disposed(by: disposeBag)
}
/*
--- Example of:distinctUntilChanged---
next(A)
next(B)
next(C)
next(D)
next(E)
completed
*/

2. distinctUntilChaged의 클로저 사용

정수 발음을 문자열로 바꾼다음 한 문자열이 다른 문자열에 속해 있다면 true를 반환하게 설정

(true = emil하지 말라)

example(of: "distinctUntilChaged") {
    let formatter = NumberFormatter()
    formatter.numberStyle = .spellOut
    Observable<NSNumber>.of(10,110,20,200,210,310)
        .distinctUntilChanged { a,b in
            print("a=\\(formatter.string(from: a)!), b=\\(formatter.string(from: b)!)")
            guard let aword = formatter.string(from: a)? .components(separatedBy: " "),
                  let bword = formatter.string(from: b)?.components(separatedBy: " ")
            else {return false}
            
            var containsMatch = false
            for aword in aword where bword.contains(aword){
                containsMatch = true
                break
            }
            return containsMatch
        }.subscribe{
            print($0)
        }.disposed(by: disposeBag)
}
/*
--- Example of:distinctUntilChaged---
next(10)
a=ten, b=one hundred ten
a=ten, b=twenty
next(20)
a=twenty, b=two hundred
next(200)
a=two hundred, b=two hundred ten
a=two hundred, b=three hundred ten
completed
*/

2. 시간과 관련된 Operator

1. Debounce

2. Throttle

Untitled