An implementation of Result interface for the option type.
This is probably the easiest way to start using Sugar, as there is no need to use describe errors. Still, because this module follows the same interface, when you need to start refactoring to more complex, monadic results you get to keep the same clean interface, making be transition straightfoward.
Usage example:
open Sugar.Option
let do_something (): string result =
if true then
Some "you could use any option type"
else
throw ()
let run (): string result =
do_something ()
>----------
( fun () ->
return "recovered"
)
In case you are wondering, the evaluation of run ()
in the example above,
will produce: string option = Some "you could use any option type"
.
module Infix : sig ... end
module Monad : S.Params.Monad with type 'a t = 'a option