1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586(**************************************************************************)(* *)(* OCaml *)(* *)(* Simon Cruanes *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Module [Seq]: functional iterators *)type+'anode=|Nil|Consof'a*'atand'at=unit->'anodeletempty()=Nilletreturnx()=Cons(x,empty)letconsxnext()=Cons(x,next)letrecappendseq1seq2()=matchseq1()with|Nil->seq2()|Cons(x,next)->Cons(x,appendnextseq2)letrecmapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->Cons(fx,mapfnext)letrecfilter_mapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->matchfxwith|None->filter_mapfnext()|Somey->Cons(y,filter_mapfnext)letrecfilterfseq()=matchseq()with|Nil->Nil|Cons(x,next)->iffxthenCons(x,filterfnext)elsefilterfnext()letrecconcatseq()=matchseq()with|Nil->Nil|Cons(x,next)->appendx(concatnext)()letrecflat_mapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->append(fx)(flat_mapfnext)()letconcat_map=flat_mapletfold_leftfaccseq=letrecauxfaccseq=matchseq()with|Nil->acc|Cons(x,next)->letacc=faccxinauxfaccnextinauxfaccseqletiterfseq=letrecauxseq=matchseq()with|Nil->()|Cons(x,next)->fx;auxnextinauxseqletrecunfoldfu()=matchfuwith|None->Nil|Some(x,u')->Cons(x,unfoldfu')