123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Options} *)type'at='aoptionlet[@inline]mapf=function|None->None|Somex->Some(fx)letmap_or~defaultf=function|None->default|Somex->fxletmap_lazydefault_fnf=function|None->default_fn()|Somex->fxletis_some=function|None->false|Some_->trueletis_none=function|None->true|Some_->falseletcomparefo1o2=matcho1,o2with|None,None->0|Some_,None->1|None,Some_->-1|Somex,Somey->fxyletequalfo1o2=matcho1,o2with|None,None->true|Some_,None|None,Some_->false|Somex,Somey->fxyletreturnx=Somexletsome=returnletnone=Nonelet[@inline]flat_mapfo=matchowith|None->None|Somex->fxlet[@inline]flat_map_lfo=matchowith|None->[]|Somex->fxlet[@inline]bindof=flat_mapfolet(>>=)=bindletpurex=Somexletk_composefgx=fx|>flat_mapglet(>=>)=k_composelet(<=<)fg=g>=>flet(<*>)fx=matchf,xwith|None,_|_,None->None|Somef,Somex->Some(fx)letor_~else_a=matchawith|None->else_|Some_->aletor_lazy~else_a=matchawith|None->else_()|Some_->alet(<+>)ab=or_~else_:baletchoicel=List.fold_left(<+>)Nonelletmap2fo1o2=matcho1,o2with|None,_|_,None->None|Somex,Somey->Some(fxy)letfilterp=function|Somexasowhenpx->o|_->Noneletif_px=ifpxthenSomexelseNoneletexistsp=function|None->false|Somex->pxletfor_allp=function|None->true|Somex->pxletiterfo=matchowith|None->()|Somex->fxletfoldfacco=matchowith|None->acc|Somex->faccxletget_or~defaultx=matchxwith|None->default|Somey->yletapply_orfx=matchfxwith|None->x|Somey->ylet(|?>)xf=apply_orfxletvaluex~default=matchxwith|None->default|Somey->yletget_exn=function|Somex->x|None->invalid_arg"CCOption.get_exn"letget_exn_ormsg=function|Somex->x|None->invalid_argmsgletget_lazydefault_fnx=matchxwith|None->default_fn()|Somey->yletsequence_ll=letrecauxaccl=matchlwith|[]->Some(List.revacc)|Somex::l'->aux(x::acc)l'|None::_->raiseExitintryaux[]lwithExit->Noneletwrap?(handler=fun_->true)fx=trySome(fx)withe->ifhandlerethenNoneelseraiseeletwrap2?(handler=fun_->true)fxy=trySome(fxy)withe->ifhandlerethenNoneelseraiseeletto_listo=matchowith|None->[]|Somex->[x]letof_list=function|x::_->Somex|[]->Noneletto_resulterr=function|None->Errorerr|Somex->Okxletto_result_lazyerr_fn=function|None->Error(err_fn())|Somex->Okxletof_result=function|Error_->None|Okx->SomexmoduleInfix=structlet(>|=)xf=mapfxlet(>>=)=(>>=)let(<*>)=(<*>)let(<$>)=maplet(<+>)=(<+>)let(|?>)=(|?>)let(let+)=(>|=)let(let*)=(>>=)let[@inline](and+)o1o2=matcho1,o2with|Somex,Somey->Some(x,y)|_->Nonelet(and*)=(and+)let(>=>)=(>=>)let(<=<)=(<=<)endincludeInfixtype'aiter=('a->unit)->unittype'agen=unit->'aoptiontype'aprinter=Format.formatter->'a->unittype'arandom_gen=Random.State.t->'aletrandomgst=ifRandom.State.boolstthenSome(gst)elseNoneexceptionExitChoiceletchoice_iters=letr=refNonein(trys(function|None->()|Some_aso->r:=o;raiseExitChoice)withExitChoice->());!rletrecchoice_seqs=matchs()with|Seq.Nil->None|Seq.Cons(Somex,_)->Somex|Seq.Cons(None,tl)->choice_seqtlletto_geno=matchowith|None->fun()->None|Some_->letfirst=reftrueinfun()->if!firstthen(first:=false;o)elseNoneletto_iterok=matchowith|None->()|Somex->kxletto_seqo()=matchowith|None->Seq.Nil|Somex->Seq.Cons(x,Seq.empty)letppppxout=function|None->Format.pp_print_stringout"None"|Somex->Format.fprintfout"@[Some %a@]"ppxxletflatten=function|Somex->x|None->Noneletreturn_ifbx=ifbthenSomexelseNone