Skip to content

Instantly share code, notes, and snippets.

@yunarta
Created February 20, 2018 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunarta/7ba453df7bb17dcd4474e6c0d323ed35 to your computer and use it in GitHub Desktop.
Save yunarta/7ba453df7bb17dcd4474e6c0d323ed35 to your computer and use it in GitHub Desktop.
rx.swift
//: 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