You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print("apply() calls the transform function on the Observable sequence: ")
34
42
35
43
lettransformed1= numbers1.apply(addOne)
36
44
lettransformed2= numbers2.apply(addOne)
45
+
lettransformed3= number3.apply(addOne)
46
+
lettransformed4= number4.apply(addOne)
37
47
38
48
transformed1.subscribe(onNext:{ result in
39
49
print(result)
@@ -42,38 +52,14 @@ example("apply a transformation") {
42
52
transformed2.subscribe(onNext:{ result in
43
53
print(result)
44
54
})
45
-
}
46
-
47
-
/*:
48
-
## apply
49
-
50
-
The `apply` operator takes a transformation function `(Single) -> Single` and applies it to the stream. The purpose of this operator is to provide syntactic sugar for applying multiple operators to the stream, while preserving the chaining operator structure of Rx.
51
-
52
-
*/
53
-
54
-
func addOne(input:Single<Int>)->Single<String>{
55
-
return input
56
-
.map{ $0 +1}
57
-
.map{"The next number is \($0)"}
58
-
}
59
-
60
-
example("apply a transformation to single"){
61
-
letnumber1=Single.just(1)
62
-
letnumber2=Single.just(100)
63
-
64
-
print("apply() calls the transform function on the Single: ")
0 commit comments