12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091(*
* Copyright (c) 2021 Craig Ferguson <craig@tarides.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)(* Extensions to the default namespace, opened throughout the Irmin codebase. *)typeread=Perms.readtypewrite=Perms.writetyperead_write=Perms.read_write(** {2 Lwt syntax} *)let(>>=)=Lwt.Infix.(>>=)let(>|=)=Lwt.Infix.(>|=)let(let*)=(>>=)let(let+)=(>|=)(** {2 Dependency extensions} *)moduleOption=structincludeOption(** @closed *)letof_result=functionOkx->Somex|Error_->NoneendmoduleList=structincludeList(** @closed *)letrecis_longer_than:typea.int->alist->bool=funlenl->iflen<0thentrueelsematchlwith[]->false|_::tl->is_longer_than(len-1)tlletmapfl=letrecauxacc=function|[]->acc[]|h::t->(aux[@tailcall])(funt'->acc(fh::t'))tinaux(funx->x)lletconcatl=letrecauxacccurrl=match(curr,l)with|[],[]->List.revacc|[],[l]->List.rev_appendaccl|[],h::t->(aux[@tailcall])accht|h::t,l->(aux[@tailcall])(h::acc)tlinaux[][]lendmoduleSeq=structincludeSeq(** @closed *)letrecdrop:typea.int->at->at=funnl()->matchl()with|l'whenn=0->l'|Nil->Nil|Cons(_,l')->drop(n-1)l'()lettake:typea.int->at->alist=letrecauxaccnl=ifn=0thenaccelsematchl()withNil->acc|Cons(x,l')->aux(x::acc)(n-1)l'infunns->List.rev(aux[]ns)letexists:typea.(a->bool)->aSeq.t->bool=funfs->letrecauxs=matchs()withSeq.Nil->false|Seq.Cons(v,s)->fv||auxsinauxsend