left If Null
Deprecated
This API is considered redundant. If this method is crucial for you, please let us know on the Arrow Github. Thanks! https://github.com/arrow-kt/arrow/issues Prefer Kotlin nullable syntax inside either DSL, or replace with explicit flatMap
Replace with
flatMap { b -> b?.right() ?: default().left() }
Content copied to clipboard
Returns Right with the existing value of Right if this is an Right with a non-null value. The returned Either.Right type is not nullable.
Returns Left(default())
if this is an Right and the existing value is null
Returns Left with the existing value of Left if this is an Left.
Example:
import arrow.core.Either.*
import arrow.core.leftIfNull
fun main() {
Right(12).leftIfNull({ -1 }) // Result: Right(12)
Right(null).leftIfNull({ -1 }) // Result: Left(-1)
Left(12).leftIfNull({ -1 }) // Result: Left(12)
}
Content copied to clipboard