123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)(** Module [Lwt_result]: explicit error handling *)openResulttype(+'a,+'b)t=('a,'b)Result.tLwt.tletreturnx=Lwt.return(Okx)letfaile=Lwt.return(Errore)letlift=Lwt.returnletokx=Lwt.map(funy->Oky)xleterrorx=Lwt.map(funy->Errory)xletmapfe=Lwt.map(function|Errore->Errore|Okx->Ok(fx))eletmap_errorfe=Lwt.map(function|Errore->Error(fe)|Okx->Okx)eletmap_errfe=map_errorfeletcatche=Lwt.catch(fun()->oke)failletget_exne=Lwt.binde(function|Okx->Lwt.returnx|Errore->Lwt.faile)letbindef=Lwt.binde(function|Errore->Lwt.return(Errore)|Okx->fx)letbind_erroref=Lwt.binde(function|Errore->fe|Okx->Lwt.return(Okx))letbind_lwtef=Lwt.binde(function|Okx->ok(fx)|Errore->faile)letbind_resultef=Lwt.map(function|Errore->Errore|Okx->fx)eletbind_lwt_erroref=Lwt.binde(function|Errore->Lwt.bind(fe)fail|Okx->returnx)letbind_lwt_erref=bind_lwt_errorefletbothab=lets=refNoneinletset_oncee=match!swith|None->s:=Somee|Some_->()inlet(a,b)=map_errorset_oncea,map_errorset_oncebinletsome_assert=function|None->assertfalse|Somee->ErroreinLwt.map(function|Okx,Oky->Ok(x,y)|Error_,Ok_|Ok_,Error_|Error_,Error_->some_assert!s)(Lwt.bothab)letiterfr=Lwt.bindr(function|Okx->fx|Error_->Lwt.return_unit)letiter_errorfr=Lwt.bindr(function|Errore->fe|Ok_->Lwt.return_unit)moduleInfix=structlet(>>=)=bindlet(>|=)ef=mapfeendmoduleLet_syntax=structmoduleLet_syntax=structletreturn=returnletmapt~f=mapftletbindt~f=bindtfletboth=bothmoduleOpen_on_rhs=structendendendmoduleSyntax=structlet(let*)=bindlet(and*)=bothlet(let+)xf=mapfxlet(and+)=bothendincludeInfix