Maybe.jl

Optional value handling for Julia
Author JuliaPreludes
Popularity
30 Stars
Updated Last
2 Years Ago
Started In
July 2020

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.

Used By Packages

No packages found.