-
Notifications
You must be signed in to change notification settings - Fork 2
/
Contents.swift
154 lines (122 loc) · 3.59 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//: # STDev Rx Extensions
/*:
> # IMPORTANT: To use **Example.playground**:
1. Open **STDevRxExt.xcworkspace**.
1. Build the **STDevRxExt-Example** scheme (**Product** → **Build**).
1. Open **Example.payground** playground in the **Project navigator**.
1. Show the Debug Area (**View** → **Debug Area** → **Show Debug Area**).
----
*/
import RxCocoa
import RxSwift
import STDevRxExt
import UIKit
/*:
## Filter Extensions
*/
example("allowTrue") {
let disposeBag = DisposeBag()
Observable.of(true, false, false, true, true)
.allowTrue()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("allowTrue Optional") {
let disposeBag = DisposeBag()
Observable.of(true, false, nil, true, nil, true)
.allowTrue()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("allowFalse") {
let disposeBag = DisposeBag()
Observable.of(true, false, false, true, false)
.allowFalse()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("allowFalse Optional") {
let disposeBag = DisposeBag()
Observable.of(true, false, nil, true, nil, true, false)
.allowFalse()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("allowTrueOrNil") {
let disposeBag = DisposeBag()
Observable.of(true, false, nil, true, nil, true, false)
.allowTrueOrNil()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("allowFalseOrNil") {
let disposeBag = DisposeBag()
Observable.of(true, false, nil, true, nil, true, false)
.allowFalseOrNil()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("Allow nil") {
let disposeBag = DisposeBag()
Observable.of(true, false, nil, true, nil, true, false)
.allowNil()
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
/*:
## Map Extensions
*/
example("map(to:)") {
let disposeBag = DisposeBag()
Observable.of(1, 5, 7, 8)
.map(to: "ping")
.subscribe(onNext: { dump($0 as String) })
.disposed(by: disposeBag)
}
example("map(at:)") {
let disposeBag = DisposeBag()
let observable = Observable.of(
Book(title: "Twenty Thousand Leagues Under the Sea", author: Author("Jules", "Verne")),
Book(title: "Hamlet", author: Author("William", "Shakespeare")),
Book(title: "Hearts of Three", author: Author("Jack", "London"))
)
observable
.map(at: \.title)
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
observable
.map(at: \.author.firstName)
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
/*:
## Cast Extensions
*/
example("cast(to:)") {
let disposeBag = DisposeBag()
Observable<CustomStringConvertible>.of("1", "5", "7", "8")
.cast(to: String.self)
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
example("forceCast(to:)") {
let disposeBag = DisposeBag()
Observable<CustomStringConvertible>.of("1", "5", "7", "8")
.forceCast(to: String.self)
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}
/*:
## Other Extensions
*/
example("update(_:with:)") {
let disposeBag = DisposeBag()
let subject = PublishSubject<Bool>()
subject
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
Observable<String>.of("1", "5", "7", "8")
.update(subject, with: true)
.subscribe(onNext: { dump($0) })
.disposed(by: disposeBag)
}