Created
March 9, 2017 20:01
-
-
Save devxoul/f5e95f4cf42918e37da39ae4059d43ba to your computer and use it in GitHub Desktop.
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
extension ObservableType { | |
typealias Accumulator<A> = (A, E) -> Observable<A> | |
func flatScan<A>(_ seed: A, accumulator: @escaping Accumulator<A>) -> Observable<A> { | |
return self | |
.scan(Observable<A>.just(seed)) { observable, current -> Observable<A> in | |
observable.flatMap { previous in | |
accumulator(previous, current) | |
} | |
} | |
.flatMap { $0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment