Created
February 27, 2020 08:21
-
-
Save ramunasjurgilas/dc2b66bffe5f88d4731d700b1caf8403 to your computer and use it in GitHub Desktop.
prefix(untilOutputFrom:) as filtering operator
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 on = PassthroughSubject<Void, Never>() | |
let strings = PassthroughSubject<String, Never>() | |
strings | |
.prefix(untilOutputFrom: on) | |
.sink(receiveValue: { print($0) }) | |
["a1", "b1", "c3", "d1", "e5"] | |
.forEach { | |
strings.send($0) | |
if $0.hasPrefix("c") { | |
on.send() | |
} | |
} | |
// Output: | |
// a1 | |
// b1 | |
// c3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment