123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100openS.Params(**
An implementation of {{!Sugar.S.Result_partials} 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"].
*)typeerror=unittype'aresult='aoptionletreturnv=Somevletthrow()=Noneletbindrf=matchrwith|None->None|Somev->fvletbind_unlessrf=matchrwith|None->f()|Somev->Somevletmaprf=matchrwith|None->None|Somev->Some(fv)let(>>=)=bindlet(>>)xy=bindx(fun()->y)moduleInfix=structlet(>---------)=bind_unlesslet(>>|)=maplet(>>)xy=bindx(fun()->Lazy.forcey)let(>>>)xy=bindx(fun_->Lazy.forcey)let(<*>)fx=f>>=funf'->x>>=funx'->return(f'x')let(<$>)fx=mapxfendletwrapf=trySome(f())with|_->Noneletunwrap=function|Somer->r|None->invalid_arg"Could not unwrap value from result"letunwrap_orrf=matchrwith|Somer->r|None->f()letexpectrmsg=matchrwith|Somer->r|None->invalid_argmsgmoduleMonad:Monadwithtype'at='aoption=structtype'at='aoptionletreturn=returnlet(>>=)=bindend