Light-weight Optional{T}
types in Julia. Inspired by the Option
type in Scala.
The Optional{T}
is a simple alias for:
const Optional{T} = Union{T, Missing}
] add https://github.com/mossr/Optionals.jl
using Optionals
let x::Optional{Int} = 10
x = missing # works!
end
let x::Int = 10
x = missing # errors!
end
function example(input::Optional{Int})
if isthere(input)
println("The input $input is not missing!")
else
println("Input is missing.")
end
end
julia> example(123)
The input 123 is not missing!
julia> example(missing)
Input is missing.
As see test_optional_customers.jl
for a more detailed example.