Publisher
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher
-
A
Combineoperator that validates upstream output and sends valid non-nil objects downstream._ = Just("Foo-bar") .validate(!.empty && .count(3...)) .sink { print($0) } // "Foo-bar"Declaration
Swift
public func compactValidate<T>(_ validator: Validator<T>) -> CompactValidatePublisher<Self> where T == Self.OutputParameters
validatorThe validator to use to validate the upstream output.
Return Value
A new
CompactValidatePublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that validates upstream output and sends valid non-nil objects downstream._ = Just("Foo-bar") .validate { !.empty && .count(3...) } .sink { print($0) } // "Foo-bar"Declaration
Swift
public func compactValidate<T>(_ validator: @escaping () -> Validator<T>) -> CompactValidatePublisher<Self> where T == OutputParameters
validatorA closure that returns validator to use to validate the upstream output.
Return Value
A new
CompactValidatePublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that validates upstream output that isValidatableand sends valid non-nil objects downstream.See also
Validatable_ = Just(MyValidatable("foo-bar")) .validate() .sink { print($0.name) } // "foo-bar"Declaration
Swift
public func compactValidate<T>() -> CompactValidatePublisher<Self> where T : Validatable, T == Self.OutputReturn Value
A new
CompactValidatePublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that validates upstream output and sends valid non-nil objects downstream. This allows you to create a customValidatoron the fly.See also
Validator_ = Just("foo-bar") .compactValidate(name: "only foo-bar") { string in guard string.lowercased() == "foo-bar" else { return nil } return string } .sink { print($0) } // "foo-bar"Declaration
Swift
public func compactValidate<T>(name: String, _ closure: @escaping (T) -> T?) -> CompactValidatePublisher<Self> where T == OutputParameters
nameThe name for the custom validator.
closureClosure that takes an instance and returns the instance if valid or
nilif not valid.
-
A
Combineoperator that validates upstream output and sends valid objects or aBasicValidationErrordownstream._ = Just("") .tryValidate(!.empty && .count(3...)) .replaceError(with: "Failed") .sink { print($0) } // "Failed"Declaration
Swift
public func tryValidate<T>(_ validator: Validator<T>) -> TryValidationPublisher<Self> where T == Self.OutputParameters
validatorThe validator to use to validate the upstream output.
Return Value
A new
TryValidationPublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that validates upstream output and sends valid objects or aBasicValidationErrordownstream._ = Just("") .tryValidate { !.empty && .count(3...) } .replaceError(with: "Failed") .sink { print($0) } // "Failed"Declaration
Swift
public func tryValidate<T>(_ validator: @escaping () -> Validator<T>) -> TryValidationPublisher<Self> where T == OutputParameters
validatorA closure that returns the validator to use to validate the upstream output.
Return Value
A new
TryValidationPublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that validates upstream output that isValidatableand sends valid objects or aBasicValidationErrordownstream._ = Just(MyValidatable()) .tryValidate() .replaceError(with: MyValidatable("Failed")) .sink { print($0.name) } // "Failed"Declaration
Swift
public func tryValidate<T>() -> TryValidationPublisher<Self> where T : Validatable, T == Self.OutputReturn Value
A new
TryValidationPublisherthat sends valid non-nil objects donwstream. -
A
Combineoperator that creates a customValidatorto validate upstream output and sends valid objects or anErrordownstream._ = Just("") .tryValidate(name: "only foo-bar") { string in guard string.lowercased() == "foo-bar" else { throw MyError() } } .replaceError(with: "Failed") .sink { print($0) } // "Failed"Declaration
Swift
public func tryValidate<T>(name: String, _ closure: @escaping (T) throws -> ()) -> TryValidationPublisher<Self> where T == OutputParameters
nameThe name for the custom validator
closureA closure used to validate the output from the upstream publisher. This closure should throw an error on invalid objects or return
Voidfor valid objects.Return Value
A new
TryValidationPublisherthat sends valid non-nil objects donwstream.
-
A
Combineoperator that validates upstream output and sends valid ornilobjects downstream._ = Just("") .validate(!.empty && .count(3...)) .replaceNil(with: "Failed") .sink { print($0) } // "Failed"Declaration
Swift
public func validate<T>(_ validator: Validator<T>) -> ValidationPublisher<Self> where T == Self.OutputParameters
validatorThe validator to use to validate the upstream output.
Return Value
A new
ValidationPublisherthat sends valid objects ornildonwstream. -
A
Combineoperator that validates upstream output and sends valid ornilobjects downstream._ = Just("") .validate { !.empty && .count(3...) } .replaceNil(with: "Failed") .sink { print($0) } // "Failed"Declaration
Swift
public func validate<T>(_ validator: @escaping () -> Validator<T>) -> ValidationPublisher<Self> where T == OutputParameters
validatorA closure that returns a validator to use to validate the upstream output.
Return Value
A new
ValidationPublisherthat sends valid objects ornildonwstream. -
A
Combineoperator that validates upstream output that isValidatableand sends valid ornilobjects downstream.See also
Validatable_ = Just(MyValidatable()) .validate() .replaceNil(with: MyValidatable("Failed")) .sink { print($0.name) } // "Failed"Declaration
Swift
public func validate<T>() -> ValidationPublisher<Self> where T : Validatable, T == Self.OutputReturn Value
A new
ValidationPublisherthat sends valid objects ornildonwstream. -
A
Combineoperator that creates a custom validator to validate upstream output and sends valid ornilobjects downstream.Seealso
Validator_ = Just("") .validate(name: "only foo-bar") { string in guard string.lowercased() == "foo-bar" else { return nil } return string } .replaceNil(with: "Failed") .sink { print($0.name) } // "Failed"Declaration
Swift
public func validate<T>(name: String, _ closure: @escaping (T) -> T?) -> ValidationPublisher<Self> where T == OutputParameters
nameThe name for the custom validator.
closureClosure that takes an instance and returns the instance if valid or
nilif not valid.
Publisher Extension Reference