Closed dmitry-novikov closed 7 years ago
What I don't like about it is that it adds a second way to get default value to existing one o.toNullable() ?: "fallback"
, that was one of the things we were trying to remove — ambiguity…
Also in a real-life case, it might be not obvious because or
is also defined for Int
, Long
and Boolean
by Kotlin stdlib which could be used as Optional<>
values quite often and might lead to wrong results of operation.
However, it's a shorter notation and fits Optional
use case quite well…
Any input @ming13, @igor-korotenko, @nostra13, @igorab?
I agree with @artem-zinnatullin about possible confusing or
considering existing binary operator.
some or 2
and some.value or 2
are similar but will produce different results.
Against it for two reasons.
or
is the same as o.toNullable() ?: value
.(o or ).method()
.Closing this for now then
It will be really handy to have infix
or
function inOptional
for fallback to default value in case ofNone
like: