Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active January 17, 2021 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/ed80515bc26c38216fb463406c00a15c to your computer and use it in GitHub Desktop.
Save jasdev/ed80515bc26c38216fb463406c00a15c to your computer and use it in GitHub Desktop.
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