Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Publisher.prefixInclusive(while:) isEven example.
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