Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file caqti_stream.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103(* Copyright (C) 2018--2019 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)moduletypeS=sigtype+'afuturetype('a,'err)t=unit->('a,'err)nodefutureand('a,'err)node=|Nil|Errorof'err|Consof'a*('a,'err)tvalfold:f:('a->'state->'state)->('a,'err)t->'state->('state,'err)resultfuturevalfold_s:f:('a->'state->('state,'err)resultfuture)->('a,'clog)t->'state->('state,[>`Congestedof'clog]as'err)resultfuturevaliter_s:f:('a->(unit,'err)resultfuture)->('a,'clog)t->(unit,[>`Congestedof'clog]as'err)resultfuturevalto_rev_list:('a,'err)t->('alist,'err)resultfuturevalto_list:('a,'err)t->('alist,'err)resultfuturevalof_list:'alist->('a,'err)tendmoduletypeFUTURE=sigtype+'afutureval(>>=):'afuture->('a->'bfuture)->'bfutureval(>|=):'afuture->('a->'b)->'bfuturevalreturn:'a->'afutureendmoduleMake(X:FUTURE):Swithtype'afuture:='aX.future=structopenXlet(>>=?)res_futuref=res_future>>=function|Oka->fa|Error_asr->returnrlet(>|=?)res_futuref=res_future>>=function|Oka->return@@Ok(fa)|Error_asr->returnrtype('a,'err)t=unit->('a,'err)nodefutureand('a,'err)node=|Nil|Errorof'err|Consof'a*('a,'err)tletrecfold~ftstate=t()>>=function|Nil->return(Okstate)|Errorerr->return(Errorerr:('a,'err)result)|Cons(a,t')->fold~ft'(fastate)letrecfold_s~ftstate=t()>>=function|Nil->return(Okstate)|Errorerr->return(Error(`Congestederr):('a,'err)result)|Cons(a,t')->fastate>>=?fold_s~ft'letreciter_s~ft=t()>>=function|Nil->return(Ok())|Errorerr->return(Error(`Congestederr):('a,'err)result)|Cons(a,t')->fa>>=?fun()->iter_s~ft'letto_rev_listt=fold~f:List.const[]letto_listt=to_rev_listt>|=?List.revletrecof_listl=fun()->matchlwith|[]->returnNil|hd::tl->return(Cons(hd,(of_listtl)))end