{"action":"opened","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/13207","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/13207/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/13207/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/13207/events","html_url":"https://github.com/JuliaLang/julia/issues/13207","id":107192276,"number":13207,"title":"Nullable and boolean operations","user":{"login":"nalimilan","id":1120448,"avatar_url":"https://avatars.githubusercontent.com/u/1120448?v=3","gravatar_id":"","url":"https://api.github.com/users/nalimilan","html_url":"https://github.com/nalimilan","followers_url":"https://api.github.com/users/nalimilan/followers","following_url":"https://api.github.com/users/nalimilan/following{/other_user}","gists_url":"https://api.github.com/users/nalimilan/gists{/gist_id}","starred_url":"https://api.github.com/users/nalimilan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nalimilan/subscriptions","organizations_url":"https://api.github.com/users/nalimilan/orgs","repos_url":"https://api.github.com/users/nalimilan/repos","events_url":"https://api.github.com/users/nalimilan/events{/privacy}","received_events_url":"https://api.github.com/users/nalimilan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-18T12:22:10Z","updated_at":"2015-09-18T12:22:10Z","closed_at":null,"body":"@davidagold raised at https://github.com/JuliaStats/NullableArrays.jl/issues/62 the issue that `Nullable{Bool}` currently doesn't work well with boolean operations, including `if`, `&&` and `||`, which has consequences on many functions, like `find`.\r\n\r\n1) Currently, the implementation in Base simply raises an error when comparing two `Nullable`:\r\n```julia\r\njulia> Nullable(1) == Nullable(1)\r\nERROR: NullException()\r\n in == at nullable.jl:52\r\n```\r\n\r\nNullableArrays.jl improves this by comparing the contents of the `Nullable`s and returning a `Nullable{Bool}`, raising an error if one of them is `NULL`.\r\n\r\n2) But even with this change, working with the result of a comparison between `Nullable`s isn't convenient, as it cannot be used with `if`, `&&` and `||`:\r\n```julia\r\njulia> y == Nullable(2)\r\nNullable(false)\r\n\r\njulia> y == Nullable(1)\r\nNullable(true)\r\n\r\njulia> if y == Nullable(1)\r\n           print(\"x\")\r\n       end\r\nERROR: TypeError: non-boolean (Nullable{Bool}) used in boolean context\r\n\r\n# Solution:\r\njulia> if get(y == Nullable(1))\r\n           print(\"x\")\r\n       end\r\nx\r\n```\r\n\r\nThis means that `NullableArray` needs to come with its own implementation for many functions to save the user from typing `get` all over the place. For example:\r\n```julia\r\njulia> z = NullableArray([1, 2])\r\n2-element NullableArray{Int64,1}:\r\n 1\r\n 2\r\n\r\njulia> find(x->x==Nullable(1), z)\r\nERROR: TypeError: non-boolean (Nullable{Bool}) used in boolean context\r\n in find at array.jl:764\r\n\r\n# Solution in the absence of a specific method:\r\njulia> find(x->get(x==Nullable(1)), z)\r\n1-element Array{Int64,1}:\r\n 1\r\n```\r\n\r\nWould it be possible to allow `Nullable{Bool}` in `if`, `&&` and `||`? The semantics are well-defined: they would be strictly equivalent  to calling `get` on the `Nullable`: `Nullable(true)` is equivalent to `true`, `Nullable(false)` is equivalent to `false`, and `Nullable()` raises an error. Special-casing `Nullable` would have the advantage that no notion of \"truthiness\" is introduced in Julia, with the drawback that it wouldn't be generic -- but maybe `Nullable` is the only type for which this definition makes sense.\r\n\r\nCc: @davidagold @johnmyleswhite "}}