PassthroughValidatedSubject

public final class PassthroughValidatedSubject<T> : ValidatedSubject<T, PassthroughSubject<T, Never>>

# PassthroughValidatedSubject

A Combine Subject that you send values to and it will send validated objects only to downstream subscribers.

     let subject = PassthroughValidatedSubject(String.self) {
         !.empty && .count(3...)
     }

     let cancellable = subject.sink { print($0) }

     subject.send("foo-bar")
     // foo-bar

     subject.send("")
     // does not get sent to downstreams.
  • Initializes a new instance.

     let subject = PassthroughValidatedSubject(String.self, !.empty && .count(3...))
    

    Declaration

    Swift

    public init(_ type: T.Type, _ validator: Validator<T>)

    Parameters

    type

    Our output type

    validator

    The validator used to validate input before sending downstream.

  • Initializes a new instance.

     let subject = PassthroughValidatedSubject(String.self) { !.empty && .count(3...) }
    

    Declaration

    Swift

    public init(_ type: T.Type, _ validator: @escaping () -> Validator<T>)

    Parameters

    type

    Our output type

    validator

    A closure that returns a validator used to validate input before sending downstream.

  • Initializes a new instance.

     let subject = PassthroughValidatedSubject<String>(!.empty && .count(3...))
    

    Declaration

    Swift

    public init(_ validator: Validator<T>)

    Parameters

    validator

    The validator used to validate input before sending downstream.

  • Initializes a new instance.

     let subject = PassthroughValidatedSubject<String> { !.empty && .count(3...) }
    

    Declaration

    Swift

    public init(_ validator: @escaping () -> Validator<T>)

    Parameters

    validator

    A closure that returns a validator used to validate input before sending downstream.

  • Initializes a new instance when our output is Validatable

     let subject = PassthroughValidatedSubject<MyValidatable>()
     // or
     let subject = PassthroughValidatedSubject(MyValidatable.self)
    

    Declaration

    Swift

    public convenience init(_ type: T.Type? = nil)

    Parameters

    type

    The Validatable type that is our output.