-
Constructs a left value.
Declaration
Swift
public static func left(_ a: A) -> Either<A, B>Parameters
aValue to be wrapped in a left of this Either type.
Return Value
A left value of Either.
-
Constructs a right value
Declaration
Swift
public static func right(_ b: B) -> Either<A, B>Parameters
bValue to be wrapped in a right of this Either type.
Return Value
A right value of Either.
-
Safe downcast.
Declaration
Swift
public static func fix(_ fa: EitherOf<A, B>) -> Either<A, B>Parameters
faValue in the higher-kind form.
Return Value
Value cast to Either.
-
Applies the provided closures based on the content of this
Eithervalue.Declaration
Swift
public func fold<C>(_ fa: (A) -> C, _ fb: (B) -> C) -> CParameters
faClosure to apply if the contained value in this
Eitheris a member of the left type.fbClosure to apply if the contained value in this
Eitheris a member of the right type.Return Value
Result of applying the corresponding closure to this value.
-
Runs the provided closures based on the content of this
Eithervalue.Declaration
Swift
public func foldRun(_ fa: (A) -> Void, _ fb: (B) -> Void)Parameters
faClosure to run if the contained value in this
Eitheris a member of the left type.fbClosure to run if the contained value in this
Eitheris a member of the right type.Return Value
Result of applying the corresponding closure to this value.
-
Checks if this value belongs to the left type.
Declaration
Swift
public var isLeft: Bool { get } -
Checks if this value belongs to the right type.
Declaration
Swift
public var isRight: Bool { get } -
Attempts to obtain a value of the left type.
This propery is unsafe and can cause fatal errors if it is invoked on a right value.
Declaration
Swift
public var leftValue: A { get } -
Attempts to obtain a value of the right type.
This property is unsafe and can cause fatal errors if it is invoked on a left value.
Declaration
Swift
public var rightValue: B { get } -
Returns the value of the right type, or
nilif it is a left value.Declaration
Swift
public var orNil: B? { get } -
Reverses the types of this either. Left values become right values and vice versa.
Declaration
Swift
public func swap() -> Either<B, A>Return Value
An either value with its types reversed respect to this one.
-
Transforms both type parameters, preserving the structure of this value.
Declaration
Swift
public func bimap<C, D>(_ fa: (A) -> C, _ fb: (B) -> D) -> Either<C, D>Parameters
faClosure to be applied when there is a left value.
fbClosure to be applied when there is a right value.
Return Value
Result of applying the corresponding closure to this value.
-
Transforms the left type parameter, preserving the structure of this value.
Declaration
Swift
public func mapLeft<C>(_ f: (A) -> C) -> Either<C, B>Parameters
fTransforming closure.
Return Value
Result of appliying the transformation to any left value in this value.
-
Returns the value from this
Either.rightvalue or allows callers to transform theEither.lefttoEither.right.Declaration
Swift
public func getOrHandle(_ f: (A) -> B) -> BParameters
fLeft transforming function.
Return Value
Value of this
Either.rightor transformation of thisEither.left. -
Converts this
Eitherto anOption.This conversion is lossy. Left values are mapped to
Option.none()and right values toOption.some(). The original `Either cannot be reconstructed from the output of this conversion.Declaration
Swift
public func toOption() -> Option<B>Return Value
An option containing a right value, or none if there is a left value.
-
Obtains the value wrapped if it is a right value, or the default value provided as an argument.
Declaration
Swift
public func getOrElse(_ defaultValue: B) -> BParameters
defaultValueValue to be returned if this value is left.
Return Value
The wrapped value if it is right; otherwise, the default value.
-
Filters the right values, providing a default left value if the do not match the provided predicate.
Declaration
Swift
public func filterOrElse(_ predicate : @escaping (B) -> Bool, _ defaultValue : A) -> Either<A, B>Parameters
predicatePredicate to test the right value.
defaultValueValue to be returned if the right value does not satisfies the predicate.
Return Value
This value, if it matches the predicate or is left; otherwise, a left value wrapping the default value.
-
Filters the right values, providing a function to transform those that do not match the predicate into a left-type value.
Declaration
Swift
public func filterOrOther(_ predicate: @escaping (B) -> Bool, _ f: @escaping (B) -> A) -> Either<A, B>Parameters
predicateFiltering predicate.
fTransforming function.
Return Value
This value, if it matches the predicate or is left; otherwise, a left value wrapping the transformation of the right value.
-
Flattens the right side of this value, providing a default value in case the wrapped value is not present.
Declaration
Swift
public func leftIfNull<BB>(_ f: @escaping @autoclosure () -> A) -> Either<A, BB> where B == Optional<BB>Parameters
fFunction providing a default value.
Return Value
An Either value where the right side is not optional.
-
Provides a Fold based on the Foldable instance of this type.
Declaration
Swift
static var fold: Fold<Either<A, B>, B> { get } -
Provides a Traversal based on the Traverse instance of this type.
Declaration
Swift
static var traversal: Traversal<Either<A, B>, B> { get }
-
Undocumented
Declaration
Swift
public typealias EachFoci = B -
Declaration
Swift
public static var each: Traversal<Either<A, B>, B> { get }
-
Provides an Iso between Either and Validated.
Declaration
Swift
static var toValidated: Iso<Either<A, B>, Validated<A, B>> { get } -
Provides a Prism focused on the left side of an Either.
Declaration
Swift
static var leftPrism: Prism<Either<A, B>, A> { get } -
Provides a Prism focused on the right side of an Either.
Declaration
Swift
static var rightPrism: Prism<Either<A, B>, B> { get }
-
Checks if this value has an element in the right side.
Declaration
Swift
func contains(_ element: B) -> BoolParameters
elementElement to check.
Return Value
Boolean value indicating if the element was found or not.
-
Returns a value from either side.
Declaration
Swift
func merge() -> A
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
-
Declaration
Swift
public func combine(_ other: Either<A, B>) -> Either<A, B>
-
Declaration
Swift
public static func empty() -> Either<A, B>
-
Converts this Either into a Result value.
Declaration
Swift
func toResult() -> Result<B, A>Return Value
A Result.success if this is an Either.right, or a Result.failure if this is an Either.left.
Install in Dash
Either Class Reference