Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created January 1, 2021 22:51
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/01a7497d7a5aa5d747c7abcb76f63773 to your computer and use it in GitHub Desktop.
Save jasdev/01a7497d7a5aa5d747c7abcb76f63773 to your computer and use it in GitHub Desktop.
Prefix while inclusive, passing values scaffolding.
extension Publisher {
func prefixInclusive(while predicate: @escaping (Output) -> Bool) -> AnyPublisher<Output, Failure> {
flatMap { value -> AnyPublisher<Output, Failure> in
if predicate(value) {
return Just(value)
.setFailureType(to: Failure.self)
.eraseToAnyPublisher()
} else {
fatalError("To be implemented.")
}
}
/* … */
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment