OptionT

public class OptionT<F, A> : OptionTOf<F, A>

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

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: OptionTOf<F, A>) -> OptionT<F, A>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to OptionT.

  • Initializes an OptionT value.

    Declaration

    Swift

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

    Parameters

    value

    An Option value wrapped in an effect.

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

    Declaration

    Swift

    public func fold<B>(_ ifEmpty: @escaping () -> B, _ f: @escaping (A) -> B) -> Kind<F, B>

    Parameters

    ifEmpty

    Closure to apply if the contained value in the nested Option is absent.

    f

    Closure to apply if the contained value in the nested Option is present.

    Return Value

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

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

    Declaration

    Swift

    public func cata<B>(_ ifEmpty: @autoclosure @escaping () -> B, _ f: @escaping (A) -> B) -> Kind<F, B>

    Parameters

    ifEmpty

    Closure to apply if the contained value in the nested Option is absent.

    f

    Closure to apply if the contained value in the nested Option is present.

    Return Value

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

  • Lifts a value by wrapping the contained value in the effect into an Option.some value.

    Declaration

    Swift

    public static func liftF(_ fb: Kind<F, A>) -> OptionT<F, A>

    Parameters

    fb

    Value to be lifted.

    Return Value

    A present Option wrapped in the effect.

  • Obtains the value of the nested Option or a default value, wrapped in the effect.

    Declaration

    Swift

    public func getOrElse(_ defaultValue: A) -> Kind<F, A>

    Parameters

    defaultValue

    Value for the absent case in the nested Option.

    Return Value

    Value contained in the nested Option if present, or the default value otherwise, wrapped in the effect.

  • Checks if the nested Option is present.

    Declaration

    Swift

    public var isDefined: Kind<F, Bool> { get }
  • Transforms the nested Option.

    Declaration

    Swift

    public func transform<B>(_ f: @escaping (Option<A>) -> Option<B>) -> OptionT<F, B>

    Parameters

    f

    Transforming function.

    Return Value

    An OptionT where the nested Option has been transformed using the provided function.

  • Flatmaps the provided function to the nested Option.

    Declaration

    Swift

    public func subflatMap<B>(_ f: @escaping (A) -> Option<B>) -> OptionT<F, B>

    Parameters

    f

    Function for the flatmap operation.

    Return Value

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

  • Convert this OptionT to an EitherT.

    Declaration

    Swift

    public func toLeft<R>(_ defaultRight: @escaping () -> R) -> EitherT<F, A, R>

    Parameters

    defaultRigth

    Function returning a default value to use as right if the OptionT is none.

    Return Value

    Returns: An EitherT containing the value as left or as right with the default value if the OptionT contains a none.

  • Convenience toLeft allowing a constant as the parameter.

    Declaration

    Swift

    public func toLeft<R>(_ defaultRight: @autoclosure @escaping () -> R) -> EitherT<F, A, R>
  • Convert this OptionT to an EitherT.

    Declaration

    Swift

    public func toRight<L>(_ defaultLeft: @escaping () -> L) -> EitherT<F, L, A>

    Parameters

    defaultLeft

    Function returning a default value to use as left if the OptionT is none.

    Return Value

    Returns: An EitherT containing the value as right or as left with the default value if the OptionT contains a none.

  • Convenience toRight allowing a constant as the parameter.

    Declaration

    Swift

    public func toRight<L>(_ defaultLeft: @autoclosure @escaping () -> L) -> EitherT<F, L, A>
  • Constructs an OptionT with a nested empty Option.

    Declaration

    Swift

    public static func none() -> OptionT<F, A>

    Return Value

    An OptionT with a nested empty Option.

  • Constructs an OptionT with a nested present Option.

    Declaration

    Swift

    public static func some(_ a: A) -> OptionT<F, A>

    Parameters

    a

    Value to be wrapped in the nested Option.

    Return Value

    An OptionT with a nested present Option.

  • Constructs an OptionT from an Option.

    Declaration

    Swift

    public static func fromOption(_ option: Option<A>) -> OptionT<F, A>

    Parameters

    option

    An Option value.

    Return Value

    An OptionT wrapping the passed argument.

  • Obtains this value if the value contained in the nested option is present, or a default value if it is absent.

    Declaration

    Swift

    public func orElse(_ defaultValue: OptionT<F, A>) -> OptionT<F, A>

    Parameters

    defaultValue

    Default value to return when the nested option is empty.

    Return Value

    This OptionT if the nested option is present, or the default value otherwise.

  • Obtains this value if the value contained in the nested option is present, or a default value if it is absent.

    Declaration

    Swift

    public func orElseF(_ defaultValue: Kind<F, Option<A>>) -> OptionT<F, A>

    Parameters

    defaultValue

    Default value to return when the nested option is empty.

    Return Value

    This OptionT if the nested option is present, or the default value otherwise.

  • Flatmaps a function that produces an effect and lifts if back to OptionT.

    Declaration

    Swift

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

    Parameters

    f

    A function producing an effect.

    Return Value

    Result of flatmapping and lifting the function to this value.

  • Obtains the value contained in the nested Option if present, or a default value otherwise.

    Declaration

    Swift

    public func getOrElseF(_ defaultValue: Kind<F, A>) -> Kind<F, A>

    Parameters

    defaultValue

    Default value to return when the nested option is empty.

    Return Value

    The value in the nested option wrapped in the effect if it is present, or the default value otherwise.