Validated
public final class Validated<E, A> : ValidatedOf<E, A>
Validated is a data type to represent valid and invalid values. It is similar to Either
, but with error accumulation in the invalid case.
-
Constructs a valid value.
Declaration
Swift
public static func valid(_ value: A) -> Validated<E, A>
Parameters
value
Valid value to be wrapped in this validated.
Return Value
A
Validated
value wrapping the parameter. -
Constructs an invalid value.
Declaration
Swift
public static func invalid(_ value: E) -> Validated<E, A>
Parameters
value
Invalid value to be wrapped in this validated.
Return Value
A
Validated
value wrapping the parameter. -
Constructs a
Validated
from anOption
value.Declaration
Swift
public static func fromOption( _ m: Option<A>, ifNone: @escaping () -> E) -> Validated<E, A>
Parameters
m
An
Option
value.ifNone
A closure providing a value for the invalid case if the option is not present.
Return Value
A
Validated
containing a valid value from the option, or an invalid wrapping the default value from the closure. -
Safe downcast.
Declaration
Swift
public static func fix(_ fa: ValidatedOf<E, A>) -> Validated<E, A>
Parameters
fa
Value in the higher-kind form.
Return Value
Value cast to Validated.
-
Applies the provided closures based on the content of this
Validated
value.Declaration
Swift
public func fold<C>(_ fe: (E) -> C, _ fa: (A) -> C) -> C
Parameters
fe
Closure to apply if the contained value is invalid.
fa
Closure to apply if the contained value is valid.
Return Value
Result of applying the corresponding closure to the contained value.
-
Checks if this value is valid.
Declaration
Swift
public var isValid: Bool { get }
-
Checks if this value is invalid.
Declaration
Swift
public var isInvalid: Bool { get }
-
Checks if the valid value in this
Validated
matches a predicate.Declaration
Swift
public func exists(_ predicate: (A) -> Bool) -> Bool
Parameters
predicate
Predicate to match the valid values.
Return Value
false
if the contained value is invalid or does not match the predicate;true
otherwise. -
Converts this value to an
Array
value.Declaration
Swift
public func toArray() -> [A]
Return Value
An empty array if this value is invalid, or a singleton array if this value is valid.
-
Wraps the invalid values of this type into a
NonEmptyArray
.Declaration
Swift
public func toValidatedNEA() -> Validated<NEA<E>, A>
Return Value
A value that is equivalent to the original one but wraps the invalid value in a
NonEmptyArray
. -
Swaps the valid and invalid types.
Declaration
Swift
public func swap() -> Validated<A, E>
Return Value
A valid value if it was invalid, and vice versa.
-
Obtains the valid value or a default value for the invalid case.
Declaration
Swift
public func getOrElse(_ defaultValue: A) -> A
Parameters
defaultValue
Default value for the invalid case.
Return Value
Valid value or default value otherwise.
-
Obtains the valid value or maps the invalid value.
Declaration
Swift
public func valueOr(_ f: (E) -> A) -> A
Parameters
f
Mapping function for invalid values.
Return Value
The valid value or the mapped invalid value.
-
Obtains this validated if is valid, or a default value if not.
Declaration
Swift
public func orElse(_ defaultValue: Validated<E, A>) -> Validated<E, A>
Parameters
defaultValue
Value to return if this value is invalid.
Return Value
This value if it is valid, or the default one otherwise.
-
Obtains the valid value or nil if it is not present
Declaration
Swift
public var orNil: A? { get }
-
Obtains the valid value or none if it is not present
Declaration
Swift
public var orNone: Option<A> { get }
-
Provides an Iso to go from/to this type to its
Kind
version.Declaration
Swift
static var fixIso: Iso<Validated<E, A>, ValidatedOf<E, A>> { get }
-
Provides a Fold based on the Foldable instance of this type.
Declaration
Swift
static var fold: Fold<Validated<E, A>, A> { get }
-
Provides a Traversal based on the Traverse instance of this type.
Declaration
Swift
static var traversal: Traversal<Validated<E, A>, A> { get }
-
Undocumented
Declaration
Swift
public typealias EachFoci = A
-
Declaration
Swift
public static var each: Traversal<Validated<E, A>, A> { get }
-
Provides an Iso between Validated and Either.
Declaration
Swift
static var toEither: Iso<Validated<E, A>, Either<E, A>> { get }
-
Provides an Iso between Validated and Try.
Declaration
Swift
static var toTry: Iso<Validated<Error, A>, Try<A>> { get }
-
Provides a polymorphic Prism focused on the valid side of a Validated.
Declaration
Swift
static func pValidPrism<B>() -> PPrism<Validated<E, A>, Validated<E, B>, A, B>
Return Value
A polymorphic Prism focused on the valid side of a Validated.
-
Provides a Prism focused on the valid side of a Validated.
Declaration
Swift
static var validPrism: Prism<Validated<E, A>, A> { get }
-
Provides a polymorphic Prism focused on the invalid side of a Validated.
Declaration
Swift
static func pInvalidPrism<EE>() -> PPrism<Validated<E, A>, Validated<EE, A>, E, EE>
Return Value
A polymorphic Prism focused on the invalid side of a Validated.
-
Provides a Prism focused on the invalid side of a Validated.
Declaration
Swift
static var invalidPrism: Prism<Validated<E, A>, E> { get }
-
Converts this Validated into a Result value.
Declaration
Swift
func toResult() -> Result<A, E>
Return Value
A Result.success if this is a Validated.valid, or a Result.failure if this is a Validated.invalid.
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
-
Declaration
Swift
public func combine(_ other: Validated<E, A>) -> Validated<E, A>