logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Documentation

       Module Result
        : sigend

       Result values.

       Result  values  handle  computation  results  and  errors  in  an explicit and declarative manner without
       resorting to exceptions.

       Since 4.08

   Resultstype('a,'e)t = ('a,'e)result =
        | Ok of'a
        | Error of'e

       The type for result values. Either a value Okv or an error Errore .

       valok : 'a->('a,'e)resultokv is Okv .

       valerror : 'e->('a,'e)resulterrore is Errore .

       valvalue : ('a,'e)result->default:'a->'avaluer~default is v if r is Okv and default otherwise.

       valget_ok : ('a,'e)result->'aget_okr is v if r is Okv and raise otherwise.

       RaisesInvalid_argument if r is Error_ .

       valget_error : ('a,'e)result->'eget_errorr is e if r is Errore and raise otherwise.

       RaisesInvalid_argument if r is Ok_ .

       valbind : ('a,'e)result->('a->('b,'e)result)->('b,'e)resultbindrf is fv if r is Okv and r if r is Error_ .

       valjoin : (('a,'e)result,'e)result->('a,'e)resultjoinrr is r if rr is Okr and rr if rr is Error_ .

       valmap : ('a->'b)->('a,'e)result->('b,'e)resultmapfr is Ok(fv) if r is Okv and r if r is Error_ .

       valmap_error : ('e->'f)->('a,'e)result->('a,'f)resultmap_errorfr is Error(fe) if r is Errore and r if r is Ok_ .

       valfold : ok:('a->'c)->error:('e->'c)->('a,'e)result->'cfold~ok~errorr is okv if r is Okv and errore if r is Errore .

       valiter : ('a->unit)->('a,'e)result->unititerfr is fv if r is Okv and () otherwise.

       valiter_error : ('e->unit)->('a,'e)result->unititer_errorfr is fe if r is Errore and () otherwise.

   Predicatesandcomparisonsvalis_ok : ('a,'e)result->boolis_okr is true if and only if r is Ok_ .

       valis_error : ('a,'e)result->boolis_errorr is true if and only if r is Error_ .

       valequal : ok:('a->'a->bool)->error:('e->'e->bool)->('a,'e)result->('a,'e)result->boolequal~ok~errorr0r1  tests equality of r0 and r1 using ok and error to respectively compare values
       wrapped by Ok_ and Error_ .

       valcompare : ok:('a->'a->int)->error:('e->'e->int)->('a,'e)result->('a,'e)result->intcompare~ok~errorr0r1  totally  orders r0 and r1 using ok and error to respectively compare values
       wrapped by Ok_ and Error_ .  Ok_ values are smaller than Error_ values.

   Convertingvalto_option : ('a,'e)result->'aoptionto_optionr is r as an option, mapping Okv to Somev and Error_ to None .

       valto_list : ('a,'e)result->'alistto_listr is [v] if r is Okv and [] otherwise.

       valto_seq : ('a,'e)result->'aSeq.tto_seqr is r as a sequence.  Okv is the singleton sequence containing  v  and  Error_  is  the  empty
       sequence.

OCamldoc                                           2025-06-12                                         Result(3o)

Module

       Module   Result

Name

       Result - Result values.

See Also