EitherT

public final class EitherT<F, A, B> : EitherTOf<F, A, B>

The EitherT transformer represents the nesting of an Either value inside any other effect. It is equivalent to Kind<F, Either<A, B>>.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: EitherTOf<F, A, B>) -> EitherT<F, A, B>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to EitherT.

  • Initializes an EitherT value.

    Declaration

    Swift

    public init(_ value: Kind<F, Either<A, B>>)

    Parameters

    value

    An Either value wrapped in an effect.

  • Applies the provided closures based on the content of the nested Either value.

    Declaration

    Swift

    public func fold<C>(_ fa: @escaping (A) -> C, _ fb: @escaping (B) -> C) -> Kind<F, C>

    Parameters

    fa

    Closure to apply if the contained value in the nested Either is a member of the left type.

    fb

    Closure to apply if the contained value in the nested Either is a member of the right type.

    Return Value

    Result of applying the corresponding closure to the nested Either, wrapped in the effect.

  • Lifts a value by nesting the contained value in the effect into an Either.right value.

    Declaration

    Swift

    public static func liftF(_ fc: Kind<F, B>) -> EitherT<F, A, B>

    Parameters

    fc

    Value to be lifted.

    Return Value

    A right Either wrapped in the effect.

  • Applies the provided closures based on the content of the nested Either value.

    Declaration

    Swift

    public func cata<C>(_ l: @escaping (A) -> C, _ r: @escaping (B) -> C) -> Kind<F, C>

    Parameters

    l

    Closure to apply if the contained value in the nested Either is a member of the left type.

    r

    Closure to apply if the contained value in the nested Either is a member of the right type.

    Return Value

    Result of applying the corresponding closure to the nested Either, wrapped in the effect.

  • Checks if the wrapped Either matches a predicate.

    Declaration

    Swift

    public func exists(_ predicate: @escaping (B) -> Bool) -> Kind<F, Bool>

    Parameters

    predicate

    Predicate to test the nested Either.

    Return Value

    A boolean value indicating if the Either matches the predicate, wrapped in the effect.

  • Transforms the nested Either.

    Declaration

    Swift

    public func transform<C, D>(_ f: @escaping (Either<A, B>) -> Either<C, D>) -> EitherT<F, C, D>

    Parameters

    f

    Transforming function.

    Return Value

    An EitherT where the nested Either has been transformed using the provided function.

  • Flatmaps the provided function to the nested Either.

    Declaration

    Swift

    public func subflatMap<C>(_ f: @escaping (B) -> Either<A, C>) -> EitherT<F, A, C>

    Parameters

    f

    Function for the flatmap operation.

    Return Value

    Result of flatmapping the provided function to the nested Either, wrapped in the effect.

  • Converts this value to an OptionT by converting the nested Either to an Option.

    Declaration

    Swift

    public func toOptionT() -> OptionT<F, B>

    Return Value

    An OptionT with the right value of the nested Either, or none if it contained a left value.

  • Transforms the left type of the nested Either.

    Declaration

    Swift

    public func mapLeft<C>(_ f: @escaping (A) -> C) -> EitherT<F, C, B>

    Parameters

    f

    Transforming function.

    Return Value

    An EitherT were the left type has been transformed.

  • Creates an EitherT with a nested left value.

    Declaration

    Swift

    public static func left(_ a: A) -> EitherT<F, A, B>

    Parameters

    a

    Value for the left case.

    Return Value

    A left Either wrapped in the effect.

  • Creates an EitherT with a nested right value.

    Declaration

    Swift

    public static func right(_ b: B) -> EitherT<F, A, B>

    Parameters

    b

    Value for the right case.

    Return Value

    A right Either wrapped in the effect.

  • Creates an EitherT from an Either value.

    Declaration

    Swift

    public static func fromEither(_ either: Either<A, B>) -> EitherT<F, A, B>

    Parameters

    either

    Either value.

    Return Value

    Either value wrapped in the effect.

  • Flatmaps a function that produces an effect and lifts it back to EitherT

    Declaration

    Swift

    public func semiflatMap<C>(_ f: @escaping (B) -> Kind<F, C>) -> EitherT<F, A, C>

    Parameters

    f

    A function producing an effect.

    Return Value

    Result of flatmapping and lifting the function in this value.