-
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.
-
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. -
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. -
Convert this
OptionT
to anEitherT
.Declaration
Swift
public func toLeft<R>(_ defaultRight: @escaping () -> R) -> EitherT<F, A, R>
Parameters
defaultRight
Function returning a default value to use as right if the
OptionT
is none.Return Value
An
EitherT
containing the value as left or as right with the default value if theOptionT
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>
Parameters
defaultRight
Function returning a default value to use as right if the
OptionT
is none.Return Value
An
EitherT
containing the value as left or as right with the default value if theOptionT
contains a none. -
Convert this
OptionT
to anEitherT
.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 theOptionT
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>
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 theOptionT
contains a none.
-
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.
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.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.