Last active
January 17, 2021 23:57
-
-
Save jasdev/ed80515bc26c38216fb463406c00a15c to your computer and use it in GitHub Desktop.
Publisher.prefixInclusive(while:) isEven example.
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
let isEven = { $0 % 2 == 0 } | |
let intSubject = PassthroughSubject<Int, Never>() | |
_ = intSubject | |
.prefixInclusive(while: isEven) | |
.sink( | |
receiveCompletion: { print($0) }, | |
receiveValue: { print($0) } | |
) | |
intSubject.send(2) | |
intSubject.send(4) | |
intSubject.send(6) | |
intSubject.send(7) | |
// Prints, | |
// 2 | |
// 4 | |
// 6 | |
// 7 | |
// finished |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment