Last active
October 19, 2021 09:54
-
-
Save rizumita/a7f0364d4fc119b35ffd to your computer and use it in GitHub Desktop.
RxSwift recursive flatMap
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
func recursive(observable: Observable<Int>) -> Observable<Int> { | |
return observable.flatMap { value -> Observable<Int> in | |
guard value < 10 else { | |
return Variable(-1).asObservable() | |
} | |
print(value) | |
return recursive(Variable(value + 1).asObservable()) | |
} | |
} | |
recursive(Variable(0).asObservable()).subscribeNext { _ in } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's so nice.