Option, Some , None vs Nullable

Is there a package which gives Option, Some and None. And why does Julia prefer Nullable?

Thanks

Why not? What Option / Some / None give over Nullable?

1 Like

Actually, Nullable is going to be deprecated soon in favor of Union{T, Void} or Union{Some{T}, Void}. See this pull request for details.

As far as I understand from the discussion, the first version of new optional types won’t support broadcast? It’s quite unfortunate since it breaks the entire monad pipeline. E.g. with Nullable{T} I could write something like:

function get_user_city(id)
    user = find_user(id)   # read from database, Nothing(user) or Nothing() if user doesn't exist
    location = getlocation.(user)
    city = getcity.(location)
    return city
end

and this would propagate empty value through all the functions. Would you recommend using Nullables.jl until this behavior is implemented in some way for the new set of types?

Indeed, at this point I intentionally excluded this part from the pull request to simplify discussions (as you can see there have already been lots of comments). I plan to file an issue to discuss it later.

There are several solutions to this. Using broadcast (as for Nullable and as you suggest) has the drawback that we would need to define broadcast on nothing to return nothing, which is not completely natural given that it’s not a container at all. It would also only work for Union{Some{T}, Void}, not for Union{T, Void}, since for the latter broadcasting would apply directly to objects or type T.

Other solutions include things like f?(x) (as in Kotlin) or a function like callornothing(f, x) (need to find a better name of course).

Anyway there’s no problem with using Nullables.jl until the new type suits you needs, it will continue to work as before (at least as long as somebody maintains it).

2 Likes

Also take a look at https://github.com/davidanthoff/DataValues.jl, it is quite similar to Nullable, but generally easier to use in a data type environment.