toArray
- 该操作符先把一个序列转成一个数组, 并作为一个单一的事件发送, 然后结束
Observable.of(1,2,3,4)
.toArray()
.subscribe(onNext: { print($0) })
.disposed(by: bag)
reduce
- reduce 接受一个初始值, 和一个操作符号
- reduce将给定的初始值, 与序列里的每个值进行累计运算. 得到一个最终结果, 并将其作为单个值发送出去
Observable.of(1,2,3,4,5)
.reduce(0, accumulator: +)
.subscribe(onNext: { print($0) })
.disposed(by: bag)
concat
- concat 会把多个Observable序列合并(串联)为一个Observable序列
- 有且只有当前一个Observable序列发出了completed事件, 才会开始发送下一个Observable序列事件
let subject91 = BehaviorSubject(value: 1)
let subject92 = BehaviorSubject(value: 2)
let variable9 = Variable(subject91)
variable9.asObservable()
.concat()
.subscribe(onNext: { print($0) })
.disposed(by: bag)
subject92.onNext(2)
subject91.onNext(1)
subject91.onNext(1)
subject91.onNext(1)
subject91.onCompleted()
variable9.value = subject92
subject92.onNext(2)