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
typeOur output type
validatorThe 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
typeOur output type
validatorA 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
validatorThe 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
validatorA closure that returns a validator used to validate input before sending downstream.
-
Initializes a new instance when our output is
Validatablelet subject = PassthroughValidatedSubject<MyValidatable>() // or let subject = PassthroughValidatedSubject(MyValidatable.self)Declaration
Swift
public convenience init(_ type: T.Type? = nil)Parameters
typeThe
Validatabletype that is our output.
PassthroughValidatedSubject Class Reference