Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 981 Bytes

README.md

File metadata and controls

33 lines (22 loc) · 981 Bytes

Maybe.jl: Optional value handling for Julia

Dev CI

Maybe.jl provides functions and macros for handling the values of type Union{Some,Nothing}; i.e., option type. The main entry point for the optional value handling is the macro @?:

julia> using Maybe

julia> data = [1, 3, 2, 1];

julia> @? data[findfirst(iseven, data)]
Some(2)

julia> y = @? data[findfirst(>=(4), data)]

julia> @assert y === nothing

Maybe.jl also provides low-level functions such as Maybe.get which is the "Maybe" variant of Base.get:

julia> Maybe.get(Dict(:a => 1), :a)
Some(1)

julia> @assert Maybe.get(Dict(:a => 1), :b) === nothing

See more in the documentation.