TryValidatedPublisher

public struct TryValidatedPublisher<T> : Publisher

TryValidatedPublisher

A top level publisher that passes validated values or BasicValidationError to downstream subscribers.

   ```
       _ = TryValidatedPublisher("foo-bar", !.empty && .count(3...))
           .replaceError(with: "Failed"
           .sink { print($0) }

       // "foo-bar"
   ```
  • The output type of this publisher.

    Declaration

    Swift

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

    Declaration

    Swift

    public typealias Failure = BasicValidationError
  • The output that will be validated before passed to downstream subscribers.

    Declaration

    Swift

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

    Declaration

    Swift

    public let validator: Validator<T>
  • Initializes a new TryValidatedPublisher with the provided output and validator.

    Declaration

    Swift

    public init(_ output: T, _ validator: Validator<T>)

    Parameters

    output

    The output to validate before sending downstreaam

    validator

    The validator to use to validate the output.

  • Attaches a downstreaam Subscriber that will receive validated values or Failure‘s

    See also

    Publisher

    Declaration

    Swift

    public func receive<S>(subscriber: S) where T == S.Input, S : Subscriber, S.Failure == Publishers.TryValidatedPublisher<T>.Failure

    Parameters

    subscriber

    The downstream subscriber to attach.

  • Initializes a new TryValidatedPublisher with the provided output when the output is also Validatable

    Declaration

    Swift

    public init(_ output: T)

    Parameters

    output

    The output to validate before sending downstreaam

    See also

    Validatable