Operation conditions of the Boolean operators and

with

  • When an incoming to the plurality Observable amb operator, he will take the first element occurring or produced Observable events, then only issue his element. Other Observable and ignore
let subject191 = PublishSubject<Int>()
let subject192 = PublishSubject<Int>()
let subject193 = PublishSubject<Int>()

subject191
    .amb(subject192)
    .amb(subject193)
    .subscribe(onNext: { print($0) })
    .disposed(by: bag)

subject192.onNext(0)
subject191.onNext(50)
subject192.onNext(1)
subject193.onNext(101)
subject193.onNext(102)
subject191.onNext(51)
subject192.onNext(2)
subject193.onNext(103)

takeWhile

  • Which in turn determine the value of each sequence Observable whether a given condition is met. When the value does not satisfy the condition of a local appearance, he automatically
Observable.of(1,2,3,4,6,1,3,8,3,5,9)
    .takeWhile {
        $0 < 7
}
.subscribe(onNext: { print($0) })
.disposed(by: bag)

takeUntil

  • In addition to subscription Observable, but also by takeUntil way we can monitor another Observable, namely notifier
  • If the notifier issue value or the complete notification, the source Observable will automatically stop sending events
let source21 = PublishSubject<String>()
let notifier21 = PublishSubject<String>()
source21.takeUntil(notifier21)
    .subscribe(onNext: { print($0) })
    .disposed(by: bag)

source21.onNext("a")
source21.onNext("b")
source21.onNext("c")

notifier21.onNext("A")

source21.onNext("d")
source21.onNext("e")
source21.onNext("f")

skipWhile

  • The method used to skip all previous events meet the conditions
  • The event does not meet the conditions of the event, and then it will not be skipped
Observable.of(1,2,3,4,5,6,7)
    .skipWhile{ $0 < 4 }
    .subscribe(onNext: { print($0) })
    .disposed(by: bag)

ship until

  • TakeUntil same as above, skipUntil addition feed Observable, by skipUntil method we can monitor another Observable, i.e. notifier
  • In contrast with takeUntil source Observable sequence of events would have been skipped by default, know notifier issued a notification value or complete
let source32 = PublishSubject<Int>()
let notifier32 = PublishSubject<Int>()
source32.skipUntil(notifier32)
    .subscribe(onNext: { print($0) })
    .disposed(by: bag)

source32.onNext(1)
source32.onNext(2)
source32.onNext(3)

notifier32.onNext(11)

source32.onNext(4)
source32.onNext(5)

notifier32.onNext(12)

source32.onNext(6)
source32.onNext(7)

Guess you like

Origin www.cnblogs.com/gchlcc/p/11847862.html