Skip to content

Commit 24d0c29

Browse files
committed
[feature/applySingle] delete separate description for single
1 parent 88ef2ed commit 24d0c29

File tree

1 file changed

+12
-26
lines changed
  • Playground/RxSwiftExtPlayground.playground/Pages/apply.xcplaygroundpage

1 file changed

+12
-26
lines changed

Playground/RxSwiftExtPlayground.playground/Pages/apply.xcplaygroundpage/Contents.swift

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,24 @@ func addOne(input: Observable<Int>) -> Observable<String> {
2626
.map { "The next number is \($0)" }
2727
}
2828

29+
func addOne(input: Single<Int>) -> Single<String> {
30+
return input
31+
.map { $0 + 1 }
32+
.map { "The next number is \($0)" }
33+
}
34+
2935
example("apply a transformation") {
3036
let numbers1 = Observable.from([1, 2, 3])
3137
let numbers2 = Observable.from([100, 101, 102])
38+
let number3 = Single.just(1)
39+
let number4 = Single.just(100)
3240

3341
print("apply() calls the transform function on the Observable sequence: ")
3442

3543
let transformed1 = numbers1.apply(addOne)
3644
let transformed2 = numbers2.apply(addOne)
45+
let transformed3 = number3.apply(addOne)
46+
let transformed4 = number4.apply(addOne)
3747

3848
transformed1.subscribe(onNext: { result in
3949
print(result)
@@ -42,38 +52,14 @@ example("apply a transformation") {
4252
transformed2.subscribe(onNext: { result in
4353
print(result)
4454
})
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-
let number1 = Single.just(1)
62-
let number2 = Single.just(100)
63-
64-
print("apply() calls the transform function on the Single: ")
6555

66-
let transformed1 = number1.apply(addOne)
67-
let transformed2 = number2.apply(addOne)
68-
69-
transformed1.subscribe(onSuccess: { result in
56+
transformed3.subscribe(onSuccess: { result in
7057
print(result)
7158
})
7259

73-
transformed2.subscribe(onSuccess: { result in
60+
transformed4.subscribe(onSuccess: { result in
7461
print(result)
7562
})
7663
}
7764

78-
7965
//: [Next](@next)

0 commit comments

Comments
 (0)