Added two additional examples to Filtering and Conditional Operators: "single with conditions".
Per suggestion by @scotteg, two additional examples were added to cover the following use cases: * A successful matching case of exactly one element * An error when repeated elements are observed
This commit is contained in:
parent
db62a3cf3f
commit
0514c03963
|
|
@ -73,9 +73,19 @@ example("single") {
|
|||
example("single with conditions") {
|
||||
let disposeBag = DisposeBag()
|
||||
|
||||
Observable.of("🐱", "🐰", "🐶", "🐸", "🐷", "🐵")
|
||||
.single { $0 == "🐸" }
|
||||
.subscribe { print($0) }
|
||||
.addDisposableTo(disposeBag)
|
||||
|
||||
Observable.of("🐱", "🐰", "🐶", "🐱", "🐰", "🐶")
|
||||
.single { $0 == "🐰" }
|
||||
.subscribe { print($0) }
|
||||
.addDisposableTo(disposeBag)
|
||||
|
||||
Observable.of("🐱", "🐰", "🐶", "🐸", "🐷", "🐵")
|
||||
.single { $0 == "🔵" }
|
||||
.subscribeNext { print($0) }
|
||||
.subscribe { print($0) }
|
||||
.addDisposableTo(disposeBag)
|
||||
}
|
||||
/*:
|
||||
|
|
|
|||
Loading…
Reference in New Issue