Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active January 17, 2021 19:55
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/0d5aae487e5982df83ef31948d4ab393 to your computer and use it in GitHub Desktop.
Save jasdev/0d5aae487e5982df83ef31948d4ab393 to your computer and use it in GitHub Desktop.
A PrefixInclusiveEvent helper type.
private enum PrefixInclusiveEvent<Output> {
/// A signal that upstream should complete successfully after a predicate-failing value.
case end
/// A signal that the inner associated value either passed the predicate or is the first not to.
case predicatePassingValueOrIncluded(Output)
/// An [enumeration property](https://www.pointfree.co/episodes/ep52-enum-properties)
/// to check if `self` is a `predicatePassingValueOrIncluded` event.
var isPredicatePassingValueOrIncluded: Bool {
guard case .predicatePassingValueOrIncluded = self else { return false }
return true
}
/// An enumeration property for quick access to the output value, if present.
var output: Output? {
guard case let .predicatePassingValueOrIncluded(inner) = self else { return nil }
return inner
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment