123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151open!Importinclude(Result:moduletypeofstructincludeResultendwithmoduleError:=Result.Error)type'at=('a,Error.t)Result.t[@@deriving_inlinecompare,equal,hash,sexp,sexp_grammar]letcompare:'a.('a->'a->int)->'at->'at->int=fun_cmp__aa__001_b__002_->Result.compare_cmp__aError.comparea__001_b__002_;;letequal:'a.('a->'a->bool)->'at->'at->bool=fun_cmp__aa__007_b__008_->Result.equal_cmp__aError.equala__007_b__008_;;lethash_fold_t:'a.(Ppx_hash_lib.Std.Hash.state->'a->Ppx_hash_lib.Std.Hash.state)->Ppx_hash_lib.Std.Hash.state->'at->Ppx_hash_lib.Std.Hash.state=fun_hash_fold_ahsvarg->Result.hash_fold_t_hash_fold_aError.hash_fold_thsvarg;;lett_of_sexp:'a.(Sexplib0.Sexp.t->'a)->Sexplib0.Sexp.t->'at=fun_of_a__013_x__015_->Result.t_of_sexp_of_a__013_Error.t_of_sexpx__015_;;letsexp_of_t:'a.('a->Sexplib0.Sexp.t)->'at->Sexplib0.Sexp.t=fun_of_a__016_x__017_->Result.sexp_of_t_of_a__016_Error.sexp_of_tx__017_;;let(t_sexp_grammar:'aSexplib0.Sexp_grammar.t->'atSexplib0.Sexp_grammar.t)=fun_'a_sexp_grammar->Result.t_sexp_grammar_'a_sexp_grammarError.t_sexp_grammar;;[@@@end]letinvariantinvariant_at=matchtwith|Oka->invariant_aa|Errorerror->Error.invarianterror;;includeApplicative.Make(structtypenonrec'at='atletreturn=returnletapplyfx=Result.combinefx~ok:(funfx->fx)~err:(fune1e2->Error.of_list[e1;e2]);;letmap=`Custommapend)moduleLet_syntax=structletreturn=returnincludeMonad_infixmoduleLet_syntax=structletreturn=returnletmap=mapletbind=bindletboth=both(* from Applicative.Make *)moduleOpen_on_rhs=structendendendletok=Result.okletis_ok=Result.is_okletis_error=Result.is_errorlettry_with?(backtrace=false)f=tryOk(f())with|exn->Error(Error.of_exnexn?backtrace:(ifbacktracethenSome`GetelseNone));;lettry_with_join?backtracef=join(try_with?backtracef)letok_exn=function|Okx->x|Errorerr->Error.raiseerr;;letof_exn?backtraceexn=Error(Error.of_exn?backtraceexn)letof_exn_result?backtrace=function|Ok_asz->z|Errorexn->of_exn?backtraceexn;;leterror?here?strictmessageasexp_of_a=Error(Error.create?here?strictmessageasexp_of_a);;leterror_ssexp=Error(Error.create_ssexp)leterror_stringmessage=Error(Error.of_stringmessage)leterrorfformat=Printf.ksprintferror_stringformatlettagt~tag=Result.map_errort~f:(Error.tag~tag)lettag_st~tag=Result.map_errort~f:(Error.tag_s~tag)lettag_s_lazyt~tag=Result.map_errort~f:(Error.tag_s_lazy~tag)lettag_argtmessageasexp_of_a=Result.map_errort~f:(fune->Error.tag_argemessageasexp_of_a);;letunimplementeds=error"unimplemented"ssexp_of_stringletcombine_errorsl=Result.map_error(Result.combine_errorsl)~f:Error.of_listletcombine_errors_unitl=Result.map(combine_errorsl)~f:(fun(_:unitlist)->())letfilter_ok_at_least_onel=letok,errs=List.partition_mapl~f:Result.to_eitherinmatchokwith|[]->Error(Error.of_listerrs)|_->Okok;;letfind_okl=matchList.find_mapl~f:Result.okwith|Somex->Okx|None->Error(Error.of_list(List.mapl~f:(function|Ok_->assertfalse|Errorerr->err)));;letfind_map_okl~f=With_return.with_return(fun{return}->Error(Error.of_list(List.mapl~f:(funelt->matchfeltwith|Ok_asx->returnx|Errorerr->err))));;letmap=Result.mapletiter=Result.iterletiter_error=Result.iter_error