Skip to content

Missing nullable operations? #16889

Closed
Closed
@TotalVerb

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    missing dataBase.missing and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions