arrow-core-data / arrow.core / getOrElse

getOrElse

fun <B> <ERROR CLASS><out <ERROR CLASS>, B>.getOrElse(default: () -> B): B

Returns the value from this Either.Right or the given argument if this is a Either.Left.

Example:

Right(12).getOrElse(17) // Result: 12
Left(12).getOrElse(17)  // Result: 17

fun <A, B> Ior<A, B>.getOrElse(default: () -> B): B fun <B> <ERROR CLASS><B>.~~getOrElse~~(default: (Throwable) -> B): B Deprecated: Try will be deleted soon as it promotes eager execution of effects, so it’s better if you work with Either’s suspend constructors or an effect handler like IO

fun <T> Option<T>.getOrElse(default: () -> T): T

Returns the option’s value if the option is nonempty, otherwise return the result of evaluating default.

Parameters

default - the default expression.fun <E, B> <ERROR CLASS><E, B>.getOrElse(default: () -> B): B

Return the Valid value, or the default if Invalid

Do you like Arrow?

Arrow Org
<