Skip to content

Instantly share code, notes, and snippets.

@bdsaglam
Created January 23, 2020 09:02
Show Gist options
  • Select an option

  • Save bdsaglam/249a9fde6d1bb6f109a5cc7ed6274993 to your computer and use it in GitHub Desktop.

Select an option

Save bdsaglam/249a9fde6d1bb6f109a5cc7ed6274993 to your computer and use it in GitHub Desktop.
RxSwift takeWhileInclusive operator
extension ObservableType {
func takeWhileInclusive(predicate: @escaping (Element) throws -> Bool) -> Observable<Element> {
let source = self.share()
let pass = source.map(predicate).startWith(true)
return Observable.zip(source, pass){ ($0, $1) }
.takeWhile { $0.1 }
.map { $0.0 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment