Created
January 23, 2020 09:02
-
-
Save bdsaglam/249a9fde6d1bb6f109a5cc7ed6274993 to your computer and use it in GitHub Desktop.
RxSwift takeWhileInclusive operator
This file contains hidden or 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 { | |
| 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