Last active
January 18, 2021 03:43
-
-
Save jasdev/cbc4aee0a184d6d4130697139799dad9 to your computer and use it in GitHub Desktop.
Tidied form of Publisher.prefixInclusive(while:).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Publisher { | |
func prefixInclusive(while predicate: @escaping (Output) -> Bool) -> AnyPublisher<Output, Failure> { | |
flatMap { value in | |
Just(PrefixInclusiveEvent.predicatePassingValueOrIncluded(value)) | |
.append(!predicate(value) ? [.end] : []) | |
.setFailureType(to: Failure.self) | |
} | |
.prefix(while: \.isPredicatePassingValueOrIncluded) | |
.compactMap(\.output) | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment