arrow-core-data / arrow.core / leftIfNull
inline fun <A, B>
EitherOf
<A, B?>.leftIfNull(default: () -> A):
Either
<A, B>
Returns Either.Right with the existing value of Either.Right if this is an Either.Right with a non-null value. The returned Either.Right type is not nullable.
Returns Left(default())
if this is an Either.Right and the existing value is null
Returns Either.Left with the existing value of Either.Left if this is an Either.Left.
Example:
Right(12).leftIfNull({ -1 }) // Result: Right(12)
Right(null).leftIfNull({ -1 }) // Result: Left(-1)
Left(12).leftIfNull({ -1 }) // Result: Left(12)
Do you like Arrow?
✖