Created
February 20, 2018 08:30
-
-
Save yunarta/7ba453df7bb17dcd4474e6c0d323ed35 to your computer and use it in GitHub Desktop.
rx.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
import RxSwiftTest | |
import RxSwift | |
func api1() -> Observable<String> { | |
return Observable.create{ (subscriber) -> Disposable in | |
print("api1 called") | |
subscriber.onNext("api1 #1") | |
subscriber.onNext("api1 #2") | |
subscriber.onCompleted() | |
return Disposables.create() | |
} | |
} | |
func api2() -> Observable<String> { | |
return Observable.create{ (subscriber) -> Disposable in | |
print("api2 called") | |
subscriber.onNext("api2 #1") | |
subscriber.onCompleted() | |
return Disposables.create() | |
} | |
} | |
func api3() -> Observable<String> { | |
return Observable.create{ (subscriber) -> Disposable in | |
print("api3 called") | |
subscriber.onNext("api3 #3") | |
subscriber.onCompleted() | |
return Disposables.create() | |
} | |
} | |
api1().flatMap { value -> Observable<String> in | |
print("map 1 \(value)") | |
return api2() | |
}.flatMap { value -> Observable<String> in | |
print("map 2 \(value)") | |
return api3() | |
}.subscribe(onNext: { (value) in | |
print(value) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment