# Option, Some , None vs Nullable

**URL:** https://discourse.julialang.org/t/option-some-none-vs-nullable/7518
**Category:** General Usage
**Created:** [December 5, 2017, 6:56am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518 "2017-12-05T06:56:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)
#### Post date: [December 5, 2017, 6:56am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/1 "2017-12-05T06:56:37Z")

</div>

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

Thanks

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [December 5, 2017, 8:08am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/2 "2017-12-05T08:08:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [December 5, 2017, 10:48am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/3 "2017-12-05T10:48:36Z")

</div>

Actually, `Nullable` is going to be deprecated soon in favor of `Union{T, Void}` or `Union{Some{T}, Void}`. See [this pull request](https://github.com/JuliaLang/julia/pull/23642) for details.

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [December 5, 2017, 11:42am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/4 "2017-12-05T11:42:16Z")

</div>

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:

```julia
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](https://github.com/JuliaArchive/Nullables.jl) until this behavior is implemented in some way for the new set of types?

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [December 5, 2017, 1:17pm UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/5 "2017-12-05T13:17:02Z")

</div>

> [@dfdx](#):
>
> As far as I understand from the discussion, the first version of new optional types won’t support broadcast?

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).

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [December 17, 2017, 5:41am UTC](https://discourse.julialang.org/t/option-some-none-vs-nullable/7518/6 "2017-12-17T05:41:59Z")

</div>

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