ValidationPublisher
public struct ValidationPublisher<Upstream> : Publisher where Upstream : Publisher
ValidationPublisher
A Combine
operator that validates upstream output and sends valid objects or nil
downstream.
See also
Publisher.validate(_:)
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 orFailure
‘sSee also
Publisher
Declaration
Parameters
subscriber
The downstream subscriber to attach.