Skip to content

Instantly share code, notes, and snippets.

@ramunasjurgilas
Created February 27, 2020 08:05
Show Gist options
  • Save ramunasjurgilas/178c4260fffe028b462393771184e918 to your computer and use it in GitHub Desktop.
Save ramunasjurgilas/178c4260fffe028b462393771184e918 to your computer and use it in GitHub Desktop.
prefix(while:) as filtering operator
let strings = PassthroughSubject<String, Never>()
strings
.prefix(while: { $0.hasSuffix("1") })
.sink(receiveValue: { print($0) })
["a1", "b1", "c3", "d1", "e5"]
.forEach {
strings.send($0)
}
// Output:
// a1
// b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment