Legend:
Library
Module
Module type
Parameter
Class
Class type
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".
type error = unit
type'a result = 'a option
val return : 'a->'b option
val throw : unit ->'a option
val bind : 'a option->('b->'c option)->'c option
val bind_unless : 'a option->(unit ->'b option)->'b option