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:
Ben Shewmake 2016-06-07 19:42:05 -06:00
parent db62a3cf3f
commit 0514c03963
1 changed files with 11 additions and 1 deletions

View File

@ -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)
}
/*: