Question Details

No question body available.

Tags

kotlin extension-methods arrow-kt

Answers (1)

Accepted Answer Available
Accepted Answer
October 29, 2025 Score: 1 Rep: 22,191 Quality: High Completeness: 80%

orNull() being deprecated doesn't mean you should simply remove it. Instead have a look at the deprecation warning, it tells you what to do instead:

orNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming

Since this deprecated method is now removed in Arrow 2, you should replace its usage with getOrNull():

fun String?.toDate(): Option {
    return Option.fromNullable(this.toDateType().map {
        it.parser(this).getOrNull()
    }.getOrNull())
}

But this function looks unnecessarily convoluted anyways, just simplify it to this:

fun String?.toDate(): Option = toDateType().flatMap { it.parser(this) }

The key here is to replace map with flatMap that replaces the Option's value with the content of another Option. Then you don't need to wrap and unwrap the value anymore, and you don't even have a need for orNull() (respectively getOrNull) at all.


In future versions of Kotlin that allow for Rich Errors, you wouldn't even use Option anymore: Logical errors (like a non-parsable date) would be integrated into the type system. toDate() would then have a return type like Date | ParseError.