This package defines julia implementations for the common types Option (aka Maybe), Either and Try, as well as one extra type ContextManager which mimics Python's with-ContextManager.
Here an example using Try to handle errors programmatically. Similar to Option, a Try is either a Const, denoting an error, or an Identity
value, which denotes success.
using DataTypesBasic # defines Try@Trydiv(1, 0) # Const(Thrown(DivideError()))@Trydiv(8, 3) # Identity(2)Using another helper package Monadic. We can combine these
into nice syntax.
using Monadic # defines @monadic# flatmap is also defined in TypeClasses.jlflatmap(f, x) = Iterators.flatten(map(f, x))
tryit =@monadic map flatmap begin
a =@Trydiv(8, 3)
b =@Tryisodd(a) ?100+ a :error("fail")
@pure a, b
end# Const(Thrown(ErrorException("fail")))For more details check out the documentation.