Closed
Description
opened on Jun 12, 2016
I was surprised that Nullable
doesn't support map
and filter
. These are pretty common and idiomatic ways to work with Nullables in other languages. Are these operations missing, or was it a conscious decision to exclude them?
It seems like it would be no issue to define filter:
filter(p, Nullable{T}()) ⇒ Nullable{T}()
filter(p, Nullable(x)) ⇒ p(x) ? Nullable(x) : Nullable{T}()
the current behaviour is a non-working lazy Filter
. I couldn't find a short way to express this operation currently.
map
on the other hand is type-unstable, so I can see why it might not be included:
map(f, Nullable{T}()) ⇒ Nullable{Union{}}()
map(f, Nullable(x)) ⇒ Nullable(f(x))
That's unfortunate. If there's no way to fix that, then maybe there's no point in keeping filter
either.
Activity