Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created March 9, 2017 20:01
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 devxoul/f5e95f4cf42918e37da39ae4059d43ba to your computer and use it in GitHub Desktop.
Save devxoul/f5e95f4cf42918e37da39ae4059d43ba to your computer and use it in GitHub Desktop.
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