ValidationPublisher

public struct ValidationPublisher<Upstream> : Publisher where Upstream : Publisher

ValidationPublisher

A Combine operator that validates upstream output and sends valid objects or nil downstream.

Usage:

_ = Just("foo-bar")
   .validate { !.empty && .count(3...) }
   .replaceNil(with: "failed")
   .sink { print($0) }

// "foo-bar"

_ = Just("fo")
   .validate { !.empty && .count(3...) }
   .replaceNil(with: "failed")
   .sink { print($0) }

// "failed"

  • The output type of this publisher.

    Declaration

    Swift

    public typealias Output = Upstream.Output?
  • The failure type of this publisher.

    Declaration

    Swift

    public typealias Failure = Upstream.Failure
  • The upstream publisher that we willl receive values from.

    Declaration

    Swift

    public let upstream: Upstream
  • The validator we will use to validate objects before sending them downstream.

    Declaration

    Swift

    public let validator: Validator<Upstream.Output>
  • Attaches a downstreaam Subscriber that will receive validated values or Failure‘s

    See also

    Publisher

    Declaration

    Swift

    public func receive<Downstream>(subscriber: Downstream) where Downstream : Subscriber, Upstream.Failure == Downstream.Failure, Downstream.Input == Upstream.Output?

    Parameters

    subscriber

    The downstream subscriber to attach.