Skip to content

Instantly share code, notes, and snippets.

@ramunasjurgilas
Created February 27, 2020 08:21
Show Gist options
  • Save ramunasjurgilas/dc2b66bffe5f88d4731d700b1caf8403 to your computer and use it in GitHub Desktop.
Save ramunasjurgilas/dc2b66bffe5f88d4731d700b1caf8403 to your computer and use it in GitHub Desktop.
prefix(untilOutputFrom:) as filtering operator
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