From 54633c0b3087060570447c777635d6e3a4b2ef7b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 8 Mar 2019 19:15:01 -0600 Subject: [PATCH] multi-version doc --- 1.0/index.html | 17 + 1.0/odoc.css | 234 ++++++ .../SequenceBigarray/.jbuilder-keep | 0 .../SequenceBigarray/index.html | 2 + 1.0/sequence.bigarray/index.html | 3 + .../sequence/Sequence/.jbuilder-keep | 0 1.0/sequence/Sequence/IO/index.html | 11 + 1.0/sequence/Sequence/Infix/index.html | 5 + 1.0/sequence/Sequence/Map/index.html | 2 + .../Sequence/Map/module-type-S/index.html | 2 + 1.0/sequence/Sequence/Set/index.html | 2 + .../Sequence/Set/module-type-S/index.html | 2 + 1.0/sequence/Sequence/index.html | 126 +++ 1.0/sequence/SequenceLabels/.jbuilder-keep | 0 1.0/sequence/SequenceLabels/IO/index.html | 11 + 1.0/sequence/SequenceLabels/Infix/index.html | 5 + 1.0/sequence/SequenceLabels/Map/index.html | 2 + .../Map/module-type-S/index.html | 2 + 1.0/sequence/SequenceLabels/Set/index.html | 2 + .../Set/module-type-S/index.html | 2 + 1.0/sequence/SequenceLabels/index.html | 103 +++ 1.0/sequence/index.html | 3 + 1.1/highlight.pack.js | 2 + 1.1/index.html | 19 + 1.1/odoc.css | 764 ++++++++++++++++++ 1.1/sequence/Sequence/.dune-keep | 0 1.1/sequence/Sequence/IO/index.html | 2 + 1.1/sequence/Sequence/Infix/index.html | 2 + 1.1/sequence/Sequence/Map/index.html | 2 + .../Sequence/Map/module-type-S/index.html | 2 + 1.1/sequence/Sequence/Set/index.html | 2 + .../Sequence/Set/module-type-S/index.html | 2 + 1.1/sequence/Sequence/index.html | 2 + 1.1/sequence/SequenceBigarray/.dune-keep | 0 1.1/sequence/SequenceBigarray/index.html | 2 + 1.1/sequence/SequenceLabels/.dune-keep | 0 1.1/sequence/SequenceLabels/IO/index.html | 2 + 1.1/sequence/SequenceLabels/Infix/index.html | 2 + 1.1/sequence/SequenceLabels/Map/index.html | 2 + .../Map/module-type-S/index.html | 2 + 1.1/sequence/SequenceLabels/Set/index.html | 2 + .../Set/module-type-S/index.html | 2 + 1.1/sequence/SequenceLabels/index.html | 2 + {1.2 => 1.1}/sequence/index.html | 2 +- 1.2/index.html | 1 - 1.2/iter/Iter/index.html | 2 +- 1.2/iter/IterLabels/index.html | 2 +- 1.2/odoc.css | 2 +- 1.2/sequence/Sequence/index.html | 2 - 1.2/sequence/SequenceLabels/index.html | 2 - index.md | 3 + 51 files changed, 1358 insertions(+), 9 deletions(-) create mode 100644 1.0/index.html create mode 100644 1.0/odoc.css rename 1.2/sequence/Sequence/.dune-keep => 1.0/sequence.bigarray/SequenceBigarray/.jbuilder-keep (100%) create mode 100644 1.0/sequence.bigarray/SequenceBigarray/index.html create mode 100644 1.0/sequence.bigarray/index.html rename 1.2/sequence/SequenceLabels/.dune-keep => 1.0/sequence/Sequence/.jbuilder-keep (100%) create mode 100644 1.0/sequence/Sequence/IO/index.html create mode 100644 1.0/sequence/Sequence/Infix/index.html create mode 100644 1.0/sequence/Sequence/Map/index.html create mode 100644 1.0/sequence/Sequence/Map/module-type-S/index.html create mode 100644 1.0/sequence/Sequence/Set/index.html create mode 100644 1.0/sequence/Sequence/Set/module-type-S/index.html create mode 100644 1.0/sequence/Sequence/index.html create mode 100644 1.0/sequence/SequenceLabels/.jbuilder-keep create mode 100644 1.0/sequence/SequenceLabels/IO/index.html create mode 100644 1.0/sequence/SequenceLabels/Infix/index.html create mode 100644 1.0/sequence/SequenceLabels/Map/index.html create mode 100644 1.0/sequence/SequenceLabels/Map/module-type-S/index.html create mode 100644 1.0/sequence/SequenceLabels/Set/index.html create mode 100644 1.0/sequence/SequenceLabels/Set/module-type-S/index.html create mode 100644 1.0/sequence/SequenceLabels/index.html create mode 100644 1.0/sequence/index.html create mode 100644 1.1/highlight.pack.js create mode 100644 1.1/index.html create mode 100644 1.1/odoc.css create mode 100644 1.1/sequence/Sequence/.dune-keep create mode 100644 1.1/sequence/Sequence/IO/index.html create mode 100644 1.1/sequence/Sequence/Infix/index.html create mode 100644 1.1/sequence/Sequence/Map/index.html create mode 100644 1.1/sequence/Sequence/Map/module-type-S/index.html create mode 100644 1.1/sequence/Sequence/Set/index.html create mode 100644 1.1/sequence/Sequence/Set/module-type-S/index.html create mode 100644 1.1/sequence/Sequence/index.html create mode 100644 1.1/sequence/SequenceBigarray/.dune-keep create mode 100644 1.1/sequence/SequenceBigarray/index.html create mode 100644 1.1/sequence/SequenceLabels/.dune-keep create mode 100644 1.1/sequence/SequenceLabels/IO/index.html create mode 100644 1.1/sequence/SequenceLabels/Infix/index.html create mode 100644 1.1/sequence/SequenceLabels/Map/index.html create mode 100644 1.1/sequence/SequenceLabels/Map/module-type-S/index.html create mode 100644 1.1/sequence/SequenceLabels/Set/index.html create mode 100644 1.1/sequence/SequenceLabels/Set/module-type-S/index.html create mode 100644 1.1/sequence/SequenceLabels/index.html rename {1.2 => 1.1}/sequence/index.html (70%) delete mode 100644 1.2/sequence/Sequence/index.html delete mode 100644 1.2/sequence/SequenceLabels/index.html diff --git a/1.0/index.html b/1.0/index.html new file mode 100644 index 0000000..f7c1c18 --- /dev/null +++ b/1.0/index.html @@ -0,0 +1,17 @@ + + + + index + + + + + +
+

OCaml package documentation

+
    +
  1. sequence 1.0
  2. +
  3. sequence.bigarray 1.0
  4. +
+ + diff --git a/1.0/odoc.css b/1.0/odoc.css new file mode 100644 index 0000000..e780892 --- /dev/null +++ b/1.0/odoc.css @@ -0,0 +1,234 @@ +@charset "UTF-8"; +/* Copyright (c) 2016 Daniel C. Bünzli. All rights reserved. + Distributed under the ISC license, see terms at the end of the file. + odoc 1.2.0 */ + +/* Reset a few things. */ + +html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre, +a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp, +small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li, +fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td, +article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup, +menu,nav,output,ruby,section,summary,time,mark,audio,video +{ margin:0; padding:0; border:0; /* outline: 0; */ + font-size:100%; font: inherit; line-height:inherit; vertical-align:baseline; + text-align: inherit; color: inherit; background: transparent; } + +table { border-collapse: collapse; border-spacing: 0; } +*, *:before, *:after { box-sizing: border-box; } + +body +{ font-family: Helvetica, "DejaVu Sans", Arial, sans-serif; + font-weight: normal; + font-size: 0.875rem; + line-height:1.25rem; + text-align: left; + min-width: 40ex; + max-width: 78ex; + padding: 1.25rem; + margin-left: 3.75rem; + color: #222; background: #FAFAFA; } + +/* Basic markup elements */ + +b, strong { font-weight: bold; } +em { font-style: italic; } + +sup { vertical-align: super; } +sub { vertical-align: sub; } +sup, sub { font-size : 0.75rem; line-height: 0; margin-left: 0.2ex; } + +p, div, img { margin-top: 1.25rem; } + +ul, ol +{ margin-top: 0.625rem; margin-bottom: 0.625rem; list-style-position: outside } + +ul { list-style-type: square } +ul > li { margin-left: 1.375rem; } +ol > li { margin-left: 1.7rem; } +li > *:first-child { margin-top: 0 } + +/* Text alignements, this should be forbidden. */ + +.left { text-align: left; } +.right { text-align: right; } +.center { text-align: center; } + +/* Links and anchors */ + +a { text-decoration:none; color:#2C5CBD; } +a:hover { box-shadow:0 1px 0 0 #2C5CBD; } +*:target /* Linked highlight */ +{ background-color: #FFF8E5; + box-shadow: 0 0 0 2px #FFF8E5, 0 0 0 3px #DDD; } + +.spec:hover > a.anchor, /* FIXME remove */ +.anchored:hover a.anchor { visibility: visible; } + +a.anchor:before { content: "#" } +a.anchor:hover { box-shadow: none; text-decoration: underline } +a.anchor +{ visibility: hidden; position: absolute; /* top: 0px; */ + margin-left: -3ex; + font-weight: normal; + font-style: normal; + padding-right: 1ex; padding-left: 1ex; /* To remain selectable */ + color: #AAA; } + +.xref-unresolved { box-shadow:0 1px 0 0 red } + +/* Section and document divisions. + Until at least 4.03 many of the modules of the stdlib start at .h7, + we restart the sequence there like h2 */ + +h1, h2, h3, h4, h5, h6, .h7, .h8, .h9, .h10 +{ font-weight: bold; margin-top: 1.25rem; } + +h1 + *, h2 + *, .h7 + * { margin-top: 0.625rem; } +h1, h2, .h7 +{ font-size: 1.25rem; + line-height: 2.4375rem; /* 2.5rem - border width */ + padding-top: 0.625rem; + border-top: solid; + border-width: 1px; + border-color: #DDD; } + +h3, .h8 { font-size: 1.125rem; } +h2 + h3, .h7 + .h8 { margin-top: 0.625rem; } + +/* Preformatted and code */ + +tt, code, pre +{ font-family: Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", + monospace; + font-weight: normal; + font-size: 0.75rem; } + +pre +{ padding-left: 0.25rem; padding-right: 0.25rem; + margin-left: -0.25rem; margin-right: -0.25rem; + padding-top: 0.3125rem; padding-bottom: 0.3125rem; + margin-top: 1.25rem; /* margin-bottom: 0.625rem; */ + line-height: 1.1875rem; + background: #F1F1F1; } + +h1 tt, h1 code, h2 tt, h2 code, .h7 tt, .h7 code { font-size: 1.125rem } +h3 tt, h3 code { font-size: 1rem } + +/* Code lexemes */ + +.keyword { font-weight: bold; } + +/* Module member specification */ + +div.def { margin-top: 0rem; text-indent: -2ex; padding-left: 2ex; } +div.def + div.doc { margin-left: 1ex; margin-top: 0.15625rem } +div.doc > *:first-child { margin-top: 0rem; } + +/* Collapsible inlined include and module */ + +details +{ border-radius: 0.5rem; + border-left: 0.2rem solid; + border-color: #FAFAFA /* Background */; + margin-left: -1.5rem; + padding-left: 1.3rem; + padding-bottom: 0.625rem; } + +details[open] { border-color: #AAA; } + +/* Records and variants FIXME */ + +div.def table { text-indent: 0em; padding:0; margin-left: -2ex; } +td.def { padding-right: 2ex } +.record td.def { padding-left:2ex; } +td.doc *:first-child { margin-top: 0em } + +/* @ tags */ + +ul.at-tag { list-style-type: none; margin-left: 0; padding: 0; } +ul.at-tag li { margin-left:0; padding:0; } +ul.at-tag li p:first-child { margin-top: 0 } /* FIXME remove */ +span.at-tag { font-weight: bold } +.at-tag.deprecated { font-weight: normal; color: crimson } +.at-tag.raise { font-weight: bold; } + +/* FIXME random other things to review. */ + +.heading +{ margin-top: 0.625rem; + border-top: solid; + border-width: 1px; + border-color: #DDD; + text-align: right; + font-weight: normal; + font-style: italic; } + +.heading + .sig { margin-top: -1.25rem; } +.heading + .parameters { margin-top: -1.25rem; } + +/* Odig package index */ + +.by-name ol, .by-tag ol, .errors ol { list-style-type: none; margin-left:0; } +.by-name ol ol, .by-tag ol ol { margin-top:0; margin-bottom: 0 } +.by-name li, .by-tag li, .errors li { margin-left:0; } + +.by-name .version { font-size: 0.625rem; color: #AAA } +.by-name nav { margin-bottom: 0.625rem } +.by-name nav a +{ text-transform: uppercase; font-size: 1.125rem; + margin-right:1ex; color: #222; display: inline-block; } + +.by-tag nav a { margin-right:1ex; color: #222; display: inline-block; } +.by-tag > ol > li { margin-top: 0.625rem; } +.by-tag > ol > li > span, +.by-tag > ol > li > ol, +.by-tag > ol > li > ol > li { display: inline-block; margin-right: 1ex; } + +/* Odig package page */ + +.package nav { display: inline; font-size: 0.875rem; font-weight: normal; } +.package .version { font-size: 0.875rem; } + +h1 + .modules, h1 + .sel { margin-top: 0.625rem } +.sel { font-weight: normal; font-style: italic; + font-size:0.875rem; margin-top:1.25rem; } +.sel + .modules { margin-top:0.625rem; + margin-bottom: 1.25rem; margin-left: 1ex; } + +.modules { margin:0; } +.modules .module { min-width:8ex; padding-right: 2ex } + +.package.info { margin: 0;} +.package.info td:first-child { font-style: italic; padding-right: 2ex; } +.package.info ul { list-style-type: none; display: inline; margin:0; } +.package.info li { display: inline-block; margin:0; margin-right:1ex; } +#info-authors li, #info-maintainers li { display:block; } + +/* Mobile adjustements. */ + +@media only screen and (max-width: 78ex) +{ body { margin: auto; } } + +/* Print adjustements. */ + +@media print +{ body { color: black; background: white; } + body nav:first-child { visibility: hidden; }} + +/*--------------------------------------------------------------------------- + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or 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. + ---------------------------------------------------------------------------*/ diff --git a/1.2/sequence/Sequence/.dune-keep b/1.0/sequence.bigarray/SequenceBigarray/.jbuilder-keep similarity index 100% rename from 1.2/sequence/Sequence/.dune-keep rename to 1.0/sequence.bigarray/SequenceBigarray/.jbuilder-keep diff --git a/1.0/sequence.bigarray/SequenceBigarray/index.html b/1.0/sequence.bigarray/SequenceBigarray/index.html new file mode 100644 index 0000000..00020c8 --- /dev/null +++ b/1.0/sequence.bigarray/SequenceBigarray/index.html @@ -0,0 +1,2 @@ + +SequenceBigarray (sequence.bigarray.SequenceBigarray)

Module SequenceBigarray

Interface and Helpers for bigarrays

val of_bigarray : ('a__) Bigarray.Array1.t ‑> 'a Sequence.t

Iterate on the elements of a 1-D array

val mmap : string ‑> char Sequence.t

Map the file into memory, and read the characters.

\ No newline at end of file diff --git a/1.0/sequence.bigarray/index.html b/1.0/sequence.bigarray/index.html new file mode 100644 index 0000000..546ff19 --- /dev/null +++ b/1.0/sequence.bigarray/index.html @@ -0,0 +1,3 @@ + +sequence_bigarray-generated (sequence.bigarray.sequence_bigarray-generated)

Library sequence.bigarray

+This library exposes the following toplevel modules:

SequenceBigarray

.

\ No newline at end of file diff --git a/1.2/sequence/SequenceLabels/.dune-keep b/1.0/sequence/Sequence/.jbuilder-keep similarity index 100% rename from 1.2/sequence/SequenceLabels/.dune-keep rename to 1.0/sequence/Sequence/.jbuilder-keep diff --git a/1.0/sequence/Sequence/IO/index.html b/1.0/sequence/Sequence/IO/index.html new file mode 100644 index 0000000..8f33384 --- /dev/null +++ b/1.0/sequence/Sequence/IO/index.html @@ -0,0 +1,11 @@ + +IO (sequence.Sequence.IO)

Module Sequence.IO

val lines_of : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t

lines_of filename reads all lines of the given file. It raises the +same exception as would opening the file and read from it, except +from End_of_file (which is caught). The file is always properly +closed. +Every time the sequence is iterated on, the file is opened again, so +different iterations might return different results

  • Parameter mode: default 0o644
  • Parameter flags: default: [Open_rdonly]
val chunks_of : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> ?⁠size:int ‑> string ‑> string t

Read chunks of the given size from the file. The last chunk might be +smaller. Behaves like lines_of regarding errors and options. +Every time the sequence is iterated on, the file is opened again, so +different iterations might return different results

val write_to : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t ‑> unit

write_to filename seq writes all strings from seq into the given +file. It takes care of opening and closing the file.

  • Parameter mode: default 0o644
  • Parameter flags: used by open_out_gen. Default: [Open_creat;Open_wronly].
val write_bytes_to : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> Bytes.t t ‑> unit
  • Since: 0.5.4
val write_lines : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t ‑> unit

Same as write_to, but intercales '\n' between each string

val write_bytes_lines : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> Bytes.t t ‑> unit
  • Since: 0.5.4
\ No newline at end of file diff --git a/1.0/sequence/Sequence/Infix/index.html b/1.0/sequence/Sequence/Infix/index.html new file mode 100644 index 0000000..6f3099e --- /dev/null +++ b/1.0/sequence/Sequence/Infix/index.html @@ -0,0 +1,5 @@ + +Infix (sequence.Sequence.Infix)

Module Sequence.Infix

val (--) : int ‑> int ‑> int t

a -- b is the range of integers from a to b, both included, +in increasing order. It will therefore be empty if a > b.

val (--^) : int ‑> int ‑> int t

a --^ b is the range of integers from b to a, both included, +in decreasing order (starts from a). +It will therefore be empty if a < b.

val (>>=) : 'a t ‑> ('a ‑> 'b t) ‑> 'b t

Monadic bind (infix version of flat_map

  • Since: 0.5
val (>|=) : 'a t ‑> ('a ‑> 'b) ‑> 'b t

Infix version of map

  • Since: 0.5
val (<*>) : ('a ‑> 'b) t ‑> 'a t ‑> 'b t

Applicative operator (product+application)

  • Since: 0.5
val (<+>) : 'a t ‑> 'a t ‑> 'a t

Concatenation of sequences

  • Since: 0.5
\ No newline at end of file diff --git a/1.0/sequence/Sequence/Map/index.html b/1.0/sequence/Sequence/Map/index.html new file mode 100644 index 0000000..5091f29 --- /dev/null +++ b/1.0/sequence/Sequence/Map/index.html @@ -0,0 +1,2 @@ + +Map (sequence.Sequence.Map)

Module Sequence.Map

module type S : sig ... end
module Adapt : functor (M : Map.S) -> S with type Adapt.key = M.key and type 'a Adapt.t = 'a M.t

Adapt a pre-existing Map module to make it sequence-aware

module Make : functor (V : Map.OrderedType) -> S with type Make.key = V.t

Create an enriched Map module, with sequence-aware functions

\ No newline at end of file diff --git a/1.0/sequence/Sequence/Map/module-type-S/index.html b/1.0/sequence/Sequence/Map/module-type-S/index.html new file mode 100644 index 0000000..95ff158 --- /dev/null +++ b/1.0/sequence/Sequence/Map/module-type-S/index.html @@ -0,0 +1,2 @@ + +S (sequence.Sequence.Map.S)

Module type Sequence.Map.S

include Map.S
type key
type +'a t
val empty : 'a t
val is_empty : 'a t ‑> bool
val mem : key ‑> 'a t ‑> bool
val add : key ‑> 'a ‑> 'a t ‑> 'a t
val singleton : key ‑> 'a ‑> 'a t
val remove : key ‑> 'a t ‑> 'a t
val merge : (key ‑> 'a option ‑> 'b option ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t
val union : (key ‑> 'a ‑> 'a ‑> 'a option) ‑> 'a t ‑> 'a t ‑> 'a t
val compare : ('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t ‑> int
val equal : ('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t ‑> bool
val iter : (key ‑> 'a ‑> unit) ‑> 'a t ‑> unit
val fold : (key ‑> 'a ‑> 'b ‑> 'b) ‑> 'a t ‑> 'b ‑> 'b
val for_all : (key ‑> 'a ‑> bool) ‑> 'a t ‑> bool
val exists : (key ‑> 'a ‑> bool) ‑> 'a t ‑> bool
val filter : (key ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t
val partition : (key ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t * 'a t
val cardinal : 'a t ‑> int
val bindings : 'a t ‑> (key * 'a) list
val min_binding : 'a t ‑> key * 'a
val min_binding_opt : 'a t ‑> (key * 'a) option
val max_binding : 'a t ‑> key * 'a
val max_binding_opt : 'a t ‑> (key * 'a) option
val choose : 'a t ‑> key * 'a
val choose_opt : 'a t ‑> (key * 'a) option
val split : key ‑> 'a t ‑> 'a t * 'a option * 'a t
val find : key ‑> 'a t ‑> 'a
val find_opt : key ‑> 'a t ‑> 'a option
val find_first : (key ‑> bool) ‑> 'a t ‑> key * 'a
val find_first_opt : (key ‑> bool) ‑> 'a t ‑> (key * 'a) option
val find_last : (key ‑> bool) ‑> 'a t ‑> key * 'a
val find_last_opt : (key ‑> bool) ‑> 'a t ‑> (key * 'a) option
val map : ('a ‑> 'b) ‑> 'a t ‑> 'b t
val mapi : (key ‑> 'a ‑> 'b) ‑> 'a t ‑> 'b t
val to_seq : 'a t ‑> (key * 'a) sequence
val of_seq : (key * 'a) sequence ‑> 'a t
val keys : 'a t ‑> key sequence
val values : 'a t ‑> 'a sequence
val to_list : 'a t ‑> (key * 'a) list
val of_list : (key * 'a) list ‑> 'a t
\ No newline at end of file diff --git a/1.0/sequence/Sequence/Set/index.html b/1.0/sequence/Sequence/Set/index.html new file mode 100644 index 0000000..a456ff9 --- /dev/null +++ b/1.0/sequence/Sequence/Set/index.html @@ -0,0 +1,2 @@ + +Set (sequence.Sequence.Set)

Module Sequence.Set

module type S : sig ... end
module Adapt : functor (X : Set.S) -> S with type Adapt.elt = X.elt and type Adapt.t = X.t

Create an enriched Set module from the given one

module Make : functor (X : Set.OrderedType) -> S with type Make.elt = X.t

Functor to build an extended Set module from an ordered type

\ No newline at end of file diff --git a/1.0/sequence/Sequence/Set/module-type-S/index.html b/1.0/sequence/Sequence/Set/module-type-S/index.html new file mode 100644 index 0000000..4ed4401 --- /dev/null +++ b/1.0/sequence/Sequence/Set/module-type-S/index.html @@ -0,0 +1,2 @@ + +S (sequence.Sequence.Set.S)

Module type Sequence.Set.S

include Set.S
type elt
type t
val empty : t
val is_empty : t ‑> bool
val mem : elt ‑> t ‑> bool
val add : elt ‑> t ‑> t
val singleton : elt ‑> t
val remove : elt ‑> t ‑> t
val union : t ‑> t ‑> t
val inter : t ‑> t ‑> t
val diff : t ‑> t ‑> t
val compare : t ‑> t ‑> int
val equal : t ‑> t ‑> bool
val subset : t ‑> t ‑> bool
val iter : (elt ‑> unit) ‑> t ‑> unit
val map : (elt ‑> elt) ‑> t ‑> t
val fold : (elt ‑> 'a ‑> 'a) ‑> t ‑> 'a ‑> 'a
val for_all : (elt ‑> bool) ‑> t ‑> bool
val exists : (elt ‑> bool) ‑> t ‑> bool
val filter : (elt ‑> bool) ‑> t ‑> t
val partition : (elt ‑> bool) ‑> t ‑> t * t
val cardinal : t ‑> int
val elements : t ‑> elt list
val min_elt : t ‑> elt
val min_elt_opt : t ‑> elt option
val max_elt : t ‑> elt
val max_elt_opt : t ‑> elt option
val choose : t ‑> elt
val choose_opt : t ‑> elt option
val split : elt ‑> t ‑> t * bool * t
val find : elt ‑> t ‑> elt
val find_opt : elt ‑> t ‑> elt option
val find_first : (elt ‑> bool) ‑> t ‑> elt
val find_first_opt : (elt ‑> bool) ‑> t ‑> elt option
val find_last : (elt ‑> bool) ‑> t ‑> elt
val find_last_opt : (elt ‑> bool) ‑> t ‑> elt option
val of_list : elt list ‑> t
val of_seq : elt sequence ‑> t
val to_seq : t ‑> elt sequence
val to_list : t ‑> elt list
val of_list : elt list ‑> t
\ No newline at end of file diff --git a/1.0/sequence/Sequence/index.html b/1.0/sequence/Sequence/index.html new file mode 100644 index 0000000..2ddc4f7 --- /dev/null +++ b/1.0/sequence/Sequence/index.html @@ -0,0 +1,126 @@ + +Sequence (sequence.Sequence)

Module Sequence

Simple and Efficient Iterators

The iterators are designed to allow easy transfer (mappings) between data +structures, without defining n^2 conversions between the n types. The +implementation relies on the assumption that a sequence can be iterated +on as many times as needed; this choice allows for high performance +of many combinators. However, for transient iterators, the persistent +function is provided, storing elements of a transient iterator +in memory; the iterator can then be used several times (See further).

Note that some combinators also return sequences (e.g. group). The +transformation is computed on the fly every time one iterates over +the resulting sequence. If a transformation performs heavy computation, +persistent can also be used as intermediate storage.

Most functions are lazy, i.e. they do not actually use their arguments +until their result is iterated on. For instance, if one calls map +on a sequence, one gets a new sequence, but nothing else happens until +this new sequence is used (by folding or iterating on it).

If a sequence is built from an iteration function that is repeatable +(i.e. calling it several times always iterates on the same set of +elements, for instance List.iter or Map.iter), then +the resulting t object is also repeatable. For one-time iter functions +such as iteration on a file descriptor or a Stream, +the persistent function can be used to iterate and store elements in +a memory structure; the result is a sequence that iterates on the elements +of this memory structure, cheaply and repeatably.

type +'a t = ('a ‑> unit) ‑> unit

A sequence of values of type 'a. If you give it a function 'a -> unit +it will be applied to every element of the sequence successively.

type +'a sequence = 'a t

NOTE Type ('a, 'b) t2 = ('a -> 'b -> unit) -> unit +has been removed and subsumed by ('a * 'b) t

type 'a equal = 'a ‑> 'a ‑> bool
type 'a hash = 'a ‑> int

Build a sequence

val from_iter : (('a ‑> unit) ‑> unit) ‑> 'a t

Build a sequence from a iter function

val from_fun : (unit ‑> 'a option) ‑> 'a t

Call the function repeatedly until it returns None. This +sequence is transient, use persistent if needed!

val empty : 'a t

Empty sequence. It contains no element.

val singleton : 'a ‑> 'a t

Singleton sequence, with exactly one element.

val doubleton : 'a ‑> 'a ‑> 'a t

Sequence with exactly two elements

val init : (int ‑> 'a) ‑> 'a t

init f is the infinite sequence f 0; f 1; f 2; ….

  • Since: 0.9
val cons : 'a ‑> 'a t ‑> 'a t

cons x l yields x, then yields from l. +Same as append (singleton x) l

val snoc : 'a t ‑> 'a ‑> 'a t

Same as cons but yields the element after iterating on l

val return : 'a ‑> 'a t

Synonym to singleton

val pure : 'a ‑> 'a t

Synonym to singleton

val repeat : 'a ‑> 'a t

Infinite sequence of the same element. You may want to look +at take and the likes if you iterate on it.

val iterate : ('a ‑> 'a) ‑> 'a ‑> 'a t

iterate f x is the infinite sequence x, f(x), f(f(x)), ...

val forever : (unit ‑> 'b) ‑> 'b t

Sequence that calls the given function to produce elements. +The sequence may be transient (depending on the function), and definitely +is infinite. You may want to use take and persistent.

val cycle : 'a t ‑> 'a t

Cycle forever through the given sequence. Assume the given sequence can +be traversed any amount of times (not transient). This yields an +infinite sequence, you should use something like take not to loop +forever.

Consume a sequence

val iter : ('a ‑> unit) ‑> 'a t ‑> unit

Consume the sequence, passing all its arguments to the function. +Basically iter f seq is just seq f.

val iteri : (int ‑> 'a ‑> unit) ‑> 'a t ‑> unit

Iterate on elements and their index in the sequence

val fold : ('a ‑> 'b ‑> 'a) ‑> 'a ‑> 'b t ‑> 'a

Fold over elements of the sequence, consuming it

val foldi : ('a ‑> int ‑> 'b ‑> 'a) ‑> 'a ‑> 'b t ‑> 'a

Fold over elements of the sequence and their index, consuming it

val fold_map : ('acc ‑> 'a ‑> 'acc * 'b) ‑> 'acc ‑> 'a t ‑> 'b t

fold_map f acc l is like map, but it carries some state as in +fold. The state is not returned, it is just used to thread some +information to the map function.

  • Since: 0.9
val fold_filter_map : ('acc ‑> 'a ‑> 'acc * 'b option) ‑> 'acc ‑> 'a t ‑> 'b t

fold_filter_map f acc l is a fold_map-like function, but the +function can choose to skip an element by retuning None.

  • Since: 0.9
val map : ('a ‑> 'b) ‑> 'a t ‑> 'b t

Map objects of the sequence into other elements, lazily

val mapi : (int ‑> 'a ‑> 'b) ‑> 'a t ‑> 'b t

Map objects, along with their index in the sequence

val map_by_2 : ('a ‑> 'a ‑> 'a) ‑> 'a t ‑> 'a t

Map objects two by two. lazily. +The last element is kept in the sequence if the count is odd.

  • Since: 0.7
val for_all : ('a ‑> bool) ‑> 'a t ‑> bool

Do all elements satisfy the predicate?

val exists : ('a ‑> bool) ‑> 'a t ‑> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a ‑> 'a t ‑> bool

Is the value a member of the sequence?

  • Parameter eq: the equality predicate to use (default (=))
  • Since: 0.5
val find : ('a ‑> 'b option) ‑> 'a t ‑> 'b option

Find the first element on which the function doesn't return None

  • Since: 0.5
val find_map : ('a ‑> 'b option) ‑> 'a t ‑> 'b option

Alias to find

  • Since: 0.10
val findi : (int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b option

Indexed version of find

  • Since: 0.9
val find_mapi : (int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b option

Alias to findi

  • Since: 0.10
val find_pred : ('a ‑> bool) ‑> 'a t ‑> 'a option

find_pred p l finds the first element of l that satisfies p, +or returns None if no element satisfies p

  • Since: 0.9
val find_pred_exn : ('a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of find_pred

  • Raises Not_found: if no such element is found
  • Since: 0.9
val length : 'a t ‑> int

How long is the sequence? Forces the sequence.

val is_empty : 'a t ‑> bool

Is the sequence empty? Forces the sequence.

Transform a sequence

val filter : ('a ‑> bool) ‑> 'a t ‑> 'a t

Filter on elements of the sequence

val append : 'a t ‑> 'a t ‑> 'a t

Append two sequences. Iterating on the result is like iterating +on the first, then on the second.

val append_l : 'a t list ‑> 'a t

Append sequences. Iterating on the result is like iterating +on the each sequence of the list in order.

  • Since: 0.11
val concat : 'a t t ‑> 'a t

Concatenate a sequence of sequences into one sequence.

val flatten : 'a t t ‑> 'a t

Alias for concat

val flat_map : ('a ‑> 'b t) ‑> 'a t ‑> 'b t

Monadic bind. Intuitively, it applies the function to every +element of the initial sequence, and calls concat. +Formerly flatMap

  • Since: 0.5
val flat_map_l : ('a ‑> 'b list) ‑> 'a t ‑> 'b t

Convenience function combining flat_map and of_list

  • Since: 0.9
val seq_list : 'a t list ‑> 'a list t

seq_list l returns all the ways to pick one element in each sub-sequence +in l. Assumes the sub-sequences can be iterated on several times.

  • Since: 0.11
val seq_list_map : ('a ‑> 'b t) ‑> 'a list ‑> 'b list t

seq_list_map f l maps f over every element of l, +then calls seq_list

  • Since: 0.11
val filter_map : ('a ‑> 'b option) ‑> 'a t ‑> 'b t

Map and only keep non-None elements +Formerly fmap

  • Since: 0.5
val filter_mapi : (int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b t

Map with indices, and only keep non-None elements

  • Since: 0.11
val filter_count : ('a ‑> bool) ‑> 'a t ‑> int

Count how many elements satisfy the given predicate

  • Since: 1.0
val intersperse : 'a ‑> 'a t ‑> 'a t

Insert the single element between every element of the sequence

val keep_some : 'a option t ‑> 'a t

filter_some l retains only elements of the form Some x. +Same as filter_map (fun x->x)

  • Since: 1.0
val keep_ok : ('a_) Result.result t ‑> 'a t

keep_ok l retains only elements of the form Ok x.

  • Since: 1.0
val keep_error : (_'e) Result.result t ‑> 'e t

keep_error l retains only elements of the form Error x.

  • Since: 1.0

Caching

val persistent : 'a t ‑> 'a t

Iterate on the sequence, storing elements in an efficient internal structure.. +The resulting sequence can be iterated on as many times as needed. +Note: calling persistent on an already persistent sequence +will still make a new copy of the sequence!

val persistent_lazy : 'a t ‑> 'a t

Lazy version of persistent. When calling persistent_lazy s, +a new sequence s' is immediately returned (without actually consuming +s) in constant time; the first time s' is iterated on, +it also consumes s and caches its content into a inner data +structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal +is interrupted prematurely (take, etc.) then s' will not be +memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t

Sort the sequence. Eager, O(n) ram and O(n ln(n)) time. +It iterates on elements of the argument sequence immediately, +before it sorts them.

val sort_uniq : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t

Sort the sequence and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> bool

Checks whether the sequence is sorted. Eager, same as sort.

  • Since: 0.9
val group_succ_by : ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a list t

Group equal consecutive elements. Linear time. +Formerly synonym to group.

  • Since: 0.6
val group_by : ?⁠hash:('a ‑> int) ‑> ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a list t

Group equal elements, disregarding their order of appearance. +The result sequence is traversable as many times as required. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.6
val count : ?⁠hash:('a ‑> int) ‑> ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. +Similar to group_by seq |> map (fun l->List.hd l, List.length l) +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val uniq : ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t

Remove consecutive duplicate elements. Basically this is +like fun seq -> map List.hd (group seq).

val product : 'a t ‑> 'b t ‑> ('a * 'b) t

Cartesian product of the sequences. When calling product a b, +the caller MUST ensure that b can be traversed as many times +as required (several times), possibly by calling persistent on it +beforehand.

val diagonal_l : 'a list ‑> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will +return the sequence of all List.nth i l, List.nth j l if i < j.

  • Since: 0.9
val diagonal : 'a t ‑> ('a * 'a) t

All pairs of distinct positions of the sequence. +Iterates only once on the sequence, which must be finite.

  • Since: 0.9
val join : join_row:('a ‑> 'b ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join ~join_row a b combines every element of a with every +element of b using join_row. If join_row returns None, then +the two elements do not combine. Assume that b allows for multiple +iterations.

val join_by : ?⁠eq:'key equal ‑> ?⁠hash:'key hash ‑> ('a ‑> 'key) ‑> ('b ‑> 'key) ‑> merge:('key ‑> 'a ‑> 'b ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join key1 key2 ~merge is a binary operation +that takes two sequences a and b, projects their +elements resp. with key1 and key2, and combine +values (x,y) from (a,b) with the same key +using merge. If merge returns None, the combination +of values is discarded. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val join_all_by : ?⁠eq:'key equal ‑> ?⁠hash:'key hash ‑> ('a ‑> 'key) ‑> ('b ‑> 'key) ‑> merge:('key ‑> 'a list ‑> 'b list ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join_all_by key1 key2 ~merge is a binary operation +that takes two sequences a and b, projects their +elements resp. with key1 and key2, and, for each key k +occurring in at least one of them: +

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination +of values is discarded, otherwise it returns Some c +and c is inserted in the result.
  • Since: 0.10
val group_join_by : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> ('b ‑> 'a) ‑> 'a t ‑> 'b t ‑> ('a * 'b list) t

group_join_by key2 associates to every element x of +the first sequence, all the elements y of the second +sequence such that eq x (key y). Elements of the first +sequences without corresponding values in the second one +are mapped to [] +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val inter : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Intersection of two collections. Each element will occur at most once +in the result. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val union : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Union of two collections. Each element will occur at most once +in the result. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val diff : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Set difference. Eager.

  • Since: 0.10
val subset : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> bool

subset a b returns true if all elements of a belong to b. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val unfoldr : ('b ‑> ('a * 'b) option) ‑> 'b ‑> 'a t

unfoldr f b will apply f to b. If it +yields Some (x,b') then x is returned +and unfoldr recurses with b'.

val scan : ('b ‑> 'a ‑> 'b) ‑> 'b ‑> 'a t ‑> 'b t

Sequence of intermediate results

val max : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a option

Max element of the sequence, using the given comparison function.

  • Returns None if the sequence is empty, Some m where m is the maximal +element otherwise
val max_exn : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of max

  • Raises Not_found: if the sequence is empty
  • Since: 0.10
val min : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a option

Min element of the sequence, using the given comparison function. +see max for more details.

val min_exn : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of min

  • Raises Not_found: if the sequence is empty
  • Since: 0.10
val sum : int t ‑> int

Sum of elements

  • Since: 0.11
val sumf : float t ‑> float

Sum of elements, using Kahan summation

  • Since: 0.11
val head : 'a t ‑> 'a option

First element, if any, otherwise None

  • Since: 0.5.1
val head_exn : 'a t ‑> 'a

First element, if any, fails

  • Raises Invalid_argument: if the sequence is empty
  • Since: 0.5.1
val take : int ‑> 'a t ‑> 'a t

Take at most n elements from the sequence. Works on infinite +sequences.

val take_while : ('a ‑> bool) ‑> 'a t ‑> 'a t

Take elements while they satisfy the predicate, then stops iterating. +Will work on an infinite sequence s if the predicate is false for at +least one element of s.

val fold_while : ('a ‑> 'b ‑> 'a * [ `Stop | `Continue ]) ‑> 'a ‑> 'b t ‑> 'a

Folds over elements of the sequence, stopping early if the accumulator +returns ('a, `Stop)

  • Since: 0.5.5
val drop : int ‑> 'a t ‑> 'a t

Drop the n first elements of the sequence. Lazy.

val drop_while : ('a ‑> bool) ‑> 'a t ‑> 'a t

Predicate version of drop

val rev : 'a t ‑> 'a t

Reverse the sequence. O(n) memory and time, needs the +sequence to be finite. The result is persistent and does +not depend on the input being repeatable.

val zip_i : 'a t ‑> (int * 'a) t
val fold2 : ('c ‑> 'a ‑> 'b ‑> 'c) ‑> 'c ‑> ('a * 'b) t ‑> 'c
val iter2 : ('a ‑> 'b ‑> unit) ‑> ('a * 'b) t ‑> unit
val map2 : ('a ‑> 'b ‑> 'c) ‑> ('a * 'b) t ‑> 'c t
val map2_2 : ('a ‑> 'b ‑> 'c) ‑> ('a ‑> 'b ‑> 'd) ‑> ('a * 'b) t ‑> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Basic data structures converters

val to_list : 'a t ‑> 'a list

Convert the sequence into a list. Preserves order of elements. +This function is tail-recursive, but consumes 2*n memory. +If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t ‑> 'a list

Get the list of the reversed sequence (more efficient than to_list)

val of_list : 'a list ‑> 'a t
val on_list : ('a t ‑> 'b t) ‑> 'a list ‑> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • Since: 0.5.2
val pair_with_idx : 'a t ‑> (int * 'a) t

Similar to zip_i but returns a normal sequence of tuples

  • Since: 0.11
val to_opt : 'a t ‑> 'a option

Alias to head

  • Since: 0.5.1
val to_array : 'a t ‑> 'a array

Convert to an array. Currently not very efficient because +an intermediate list is used.

val of_array : 'a array ‑> 'a t
val of_array_i : 'a array ‑> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array ‑> int ‑> int ‑> 'a t

array_slice a i j Sequence of elements whose indexes range +from i to j

val of_opt : 'a option ‑> 'a t

Iterate on 0 or 1 values.

  • Since: 0.5.1
val of_stream : 'a Stream.t ‑> 'a t

Sequence of elements of a stream (usable only once)

val to_stream : 'a t ‑> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t ‑> 'a t ‑> unit

Push elements of the sequence on the stack

val of_stack : 'a Stack.t ‑> 'a t

Sequence of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t ‑> 'a t ‑> unit

Push elements of the sequence into the queue

val of_queue : 'a Queue.t ‑> 'a t

Sequence of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t ‑> ('a * 'b) t ‑> unit

Add elements of the sequence to the hashtable, with +Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t ‑> ('a * 'b) t ‑> unit

Add elements of the sequence to the hashtable, with +Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t ‑> ('a'b) Hashtbl.t

Build a hashtable from a sequence of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t ‑> ('a * 'b) t

Sequence of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t ‑> 'a t
val hashtbl_values : ('a'b) Hashtbl.t ‑> 'b t
val of_str : string ‑> char t
val to_str : char t ‑> string
val concat_str : string t ‑> string

Concatenate strings together, eagerly. +Also see intersperse to add a separator.

  • Since: 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on +a transient iterator

val of_in_channel : Pervasives.in_channel ‑> char t

Iterates on characters of the input (can block when one +iterates over the sequence). If you need to iterate +several times on this sequence, use persistent.

  • Raises OneShotSequence: when used more than once.
val to_buffer : char t ‑> Buffer.t ‑> unit

Copy content of the sequence into the buffer

val int_range : start:int ‑> stop:int ‑> int t
val int_range_dec : start:int ‑> stop:int ‑> int t
val int_range_by : step:int ‑> int ‑> int ‑> int t

int_range_by ~step i j is the range starting at i, including j, +where the difference between successive elements is step. +use a negative step for a decreasing sequence.

  • Raises Invalid_argument: if step=0
val bools : bool t

Iterates on true and false

  • Since: 0.7
val of_set : (module Set.S with type elt = 'a and type t = 'b) ‑> 'b ‑> 'a t

Convert the given set to a sequence. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) ‑> 'a t ‑> 'b

Convert the sequence to a set, given the proper set module

type 'a gen = unit ‑> 'a option
type 'a klist = unit ‑> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen ‑> 'a t

Traverse eagerly the generator and build a sequence from it

val to_gen : 'a t ‑> 'a gen

Make the sequence persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist ‑> 'a t

Iterate on the lazy list

val to_klist : 'a t ‑> 'a klist

Make the sequence persistent and then iterate on it. Eager.

Functorial conversions between sets and sequences

module Set : sig ... end

Conversion between maps and sequences.

module Map : sig ... end

Infinite sequences of random values

val random_int : int ‑> int t

Infinite sequence of random integers between 0 and +the given higher bound (see Random.int)

val random_bool : bool t

Infinite sequence of random bool values

val random_float : float ‑> float t
val random_array : 'a array ‑> 'a t

Sequence of choices of an element in the array

val random_list : 'a list ‑> 'a t

Infinite sequence of random elements of the list. Basically the +same as random_array.

val shuffle : 'a t ‑> 'a t

shuffle seq returns a perfect shuffle of seq. +Uses O(length seq) memory and time. Eager.

  • Since: 0.7
val shuffle_buffer : int ‑> 'a t ‑> 'a t

shuffle_buffer n seq returns a sequence of element of seq in random +order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the sequence are consumed immediately. The +rest is consumed lazily.

  • Since: 0.7

Sampling

val sample : int ‑> 'a t ‑> 'a array

sample n seq returns k samples of seq, with uniform probability. +It will consume the sequence and use O(n) memory.

It returns an array of size min (length seq) n.

  • Since: 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int ‑> int ‑> int t

a -- b is the range of integers from a to b, both included, +in increasing order. It will therefore be empty if a > b.

val (--^) : int ‑> int ‑> int t

a --^ b is the range of integers from b to a, both included, +in decreasing order (starts from a). +It will therefore be empty if a < b.

val (>>=) : 'a t ‑> ('a ‑> 'b t) ‑> 'b t

Monadic bind (infix version of flat_map

  • Since: 0.5
val (>|=) : 'a t ‑> ('a ‑> 'b) ‑> 'b t

Infix version of map

  • Since: 0.5
val (<*>) : ('a ‑> 'b) t ‑> 'a t ‑> 'b t

Applicative operator (product+application)

  • Since: 0.5
val (<+>) : 'a t ‑> 'a t ‑> 'a t

Concatenation of sequences

  • Since: 0.5

Pretty printing of sequences

val pp_seq : ?⁠sep:string ‑> (Format.formatter ‑> 'a ‑> unit) ‑> Format.formatter ‑> 'a t ‑> unit

Pretty print a sequence of 'a, using the given pretty printer +to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string ‑> (Buffer.t ‑> 'a ‑> unit) ‑> Buffer.t ‑> 'a t ‑> unit

Print into a buffer

val to_string : ?⁠sep:string ‑> ('a ‑> string) ‑> 'a t ‑> string

Print into a string

Basic IO

Very basic interface to manipulate files as sequence of chunks/lines. The +sequences take care of opening and closing files properly; every time +one iterates over a sequence, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

      Sequence.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

      Sequence.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

      Sequence.IO.lines "a" |> Sequence.to_list
module IO : sig ... end
\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/.jbuilder-keep b/1.0/sequence/SequenceLabels/.jbuilder-keep new file mode 100644 index 0000000..e69de29 diff --git a/1.0/sequence/SequenceLabels/IO/index.html b/1.0/sequence/SequenceLabels/IO/index.html new file mode 100644 index 0000000..bb2b41e --- /dev/null +++ b/1.0/sequence/SequenceLabels/IO/index.html @@ -0,0 +1,11 @@ + +IO (sequence.SequenceLabels.IO)

Module SequenceLabels.IO

val lines_of : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t

lines_of filename reads all lines of the given file. It raises the +same exception as would opening the file and read from it, except +from End_of_file (which is caught). The file is always properly +closed. +Every time the sequence is iterated on, the file is opened again, so +different iterations might return different results

  • Parameter mode: default 0o644
  • Parameter flags: default: [Open_rdonly]
val chunks_of : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> ?⁠size:int ‑> string ‑> string t

Read chunks of the given size from the file. The last chunk might be +smaller. Behaves like lines_of regarding errors and options. +Every time the sequence is iterated on, the file is opened again, so +different iterations might return different results

val write_to : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t ‑> unit

write_to filename seq writes all strings from seq into the given +file. It takes care of opening and closing the file.

  • Parameter mode: default 0o644
  • Parameter flags: used by open_out_gen. Default: [Open_creat;Open_wronly].
val write_bytes_to : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> Bytes.t t ‑> unit
  • Since: 0.5.4
val write_lines : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> string t ‑> unit

Same as write_to, but intercales '\n' between each string

val write_bytes_lines : ?⁠mode:int ‑> ?⁠flags:Pervasives.open_flag list ‑> string ‑> Bytes.t t ‑> unit
  • Since: 0.5.4
\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/Infix/index.html b/1.0/sequence/SequenceLabels/Infix/index.html new file mode 100644 index 0000000..2998217 --- /dev/null +++ b/1.0/sequence/SequenceLabels/Infix/index.html @@ -0,0 +1,5 @@ + +Infix (sequence.SequenceLabels.Infix)

Module SequenceLabels.Infix

val (--) : int ‑> int ‑> int t

a -- b is the range of integers from a to b, both included, +in increasing order. It will therefore be empty if a > b.

val (--^) : int ‑> int ‑> int t

a --^ b is the range of integers from b to a, both included, +in decreasing order (starts from a). +It will therefore be empty if a < b.

val (>>=) : 'a t ‑> ('a ‑> 'b t) ‑> 'b t

Monadic bind (infix version of flat_map

  • Since: 0.5
val (>|=) : 'a t ‑> ('a ‑> 'b) ‑> 'b t

Infix version of map

  • Since: 0.5
val (<*>) : ('a ‑> 'b) t ‑> 'a t ‑> 'b t

Applicative operator (product+application)

  • Since: 0.5
val (<+>) : 'a t ‑> 'a t ‑> 'a t

Concatenation of sequences

  • Since: 0.5
\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/Map/index.html b/1.0/sequence/SequenceLabels/Map/index.html new file mode 100644 index 0000000..faeec97 --- /dev/null +++ b/1.0/sequence/SequenceLabels/Map/index.html @@ -0,0 +1,2 @@ + +Map (sequence.SequenceLabels.Map)

Module SequenceLabels.Map

module type S : sig ... end
module Adapt : functor (M : Map.S) -> S with type Adapt.key = M.key and type 'a Adapt.t = 'a M.t

Adapt a pre-existing Map module to make it sequence-aware

module Make : functor (V : Map.OrderedType) -> S with type Make.key = V.t

Create an enriched Map module, with sequence-aware functions

\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/Map/module-type-S/index.html b/1.0/sequence/SequenceLabels/Map/module-type-S/index.html new file mode 100644 index 0000000..4b73bb1 --- /dev/null +++ b/1.0/sequence/SequenceLabels/Map/module-type-S/index.html @@ -0,0 +1,2 @@ + +S (sequence.SequenceLabels.Map.S)

Module type SequenceLabels.Map.S

include Map.S
type key
type +'a t
val empty : 'a t
val is_empty : 'a t ‑> bool
val mem : key ‑> 'a t ‑> bool
val add : key ‑> 'a ‑> 'a t ‑> 'a t
val singleton : key ‑> 'a ‑> 'a t
val remove : key ‑> 'a t ‑> 'a t
val merge : (key ‑> 'a option ‑> 'b option ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t
val union : (key ‑> 'a ‑> 'a ‑> 'a option) ‑> 'a t ‑> 'a t ‑> 'a t
val compare : ('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t ‑> int
val equal : ('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t ‑> bool
val iter : (key ‑> 'a ‑> unit) ‑> 'a t ‑> unit
val fold : (key ‑> 'a ‑> 'b ‑> 'b) ‑> 'a t ‑> 'b ‑> 'b
val for_all : (key ‑> 'a ‑> bool) ‑> 'a t ‑> bool
val exists : (key ‑> 'a ‑> bool) ‑> 'a t ‑> bool
val filter : (key ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t
val partition : (key ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t * 'a t
val cardinal : 'a t ‑> int
val bindings : 'a t ‑> (key * 'a) list
val min_binding : 'a t ‑> key * 'a
val min_binding_opt : 'a t ‑> (key * 'a) option
val max_binding : 'a t ‑> key * 'a
val max_binding_opt : 'a t ‑> (key * 'a) option
val choose : 'a t ‑> key * 'a
val choose_opt : 'a t ‑> (key * 'a) option
val split : key ‑> 'a t ‑> 'a t * 'a option * 'a t
val find : key ‑> 'a t ‑> 'a
val find_opt : key ‑> 'a t ‑> 'a option
val find_first : (key ‑> bool) ‑> 'a t ‑> key * 'a
val find_first_opt : (key ‑> bool) ‑> 'a t ‑> (key * 'a) option
val find_last : (key ‑> bool) ‑> 'a t ‑> key * 'a
val find_last_opt : (key ‑> bool) ‑> 'a t ‑> (key * 'a) option
val map : ('a ‑> 'b) ‑> 'a t ‑> 'b t
val mapi : (key ‑> 'a ‑> 'b) ‑> 'a t ‑> 'b t
val to_seq : 'a t ‑> (key * 'a) sequence
val of_seq : (key * 'a) sequence ‑> 'a t
val keys : 'a t ‑> key sequence
val values : 'a t ‑> 'a sequence
val to_list : 'a t ‑> (key * 'a) list
val of_list : (key * 'a) list ‑> 'a t
\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/Set/index.html b/1.0/sequence/SequenceLabels/Set/index.html new file mode 100644 index 0000000..5837a2e --- /dev/null +++ b/1.0/sequence/SequenceLabels/Set/index.html @@ -0,0 +1,2 @@ + +Set (sequence.SequenceLabels.Set)

Module SequenceLabels.Set

module type S : sig ... end
module Adapt : functor (X : Set.S) -> S with type Adapt.elt = X.elt and type Adapt.t = X.t

Create an enriched Set module from the given one

module Make : functor (X : Set.OrderedType) -> S with type Make.elt = X.t

Functor to build an extended Set module from an ordered type

\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/Set/module-type-S/index.html b/1.0/sequence/SequenceLabels/Set/module-type-S/index.html new file mode 100644 index 0000000..1145ef1 --- /dev/null +++ b/1.0/sequence/SequenceLabels/Set/module-type-S/index.html @@ -0,0 +1,2 @@ + +S (sequence.SequenceLabels.Set.S)

Module type SequenceLabels.Set.S

include Set.S
type elt
type t
val empty : t
val is_empty : t ‑> bool
val mem : elt ‑> t ‑> bool
val add : elt ‑> t ‑> t
val singleton : elt ‑> t
val remove : elt ‑> t ‑> t
val union : t ‑> t ‑> t
val inter : t ‑> t ‑> t
val diff : t ‑> t ‑> t
val compare : t ‑> t ‑> int
val equal : t ‑> t ‑> bool
val subset : t ‑> t ‑> bool
val iter : (elt ‑> unit) ‑> t ‑> unit
val map : (elt ‑> elt) ‑> t ‑> t
val fold : (elt ‑> 'a ‑> 'a) ‑> t ‑> 'a ‑> 'a
val for_all : (elt ‑> bool) ‑> t ‑> bool
val exists : (elt ‑> bool) ‑> t ‑> bool
val filter : (elt ‑> bool) ‑> t ‑> t
val partition : (elt ‑> bool) ‑> t ‑> t * t
val cardinal : t ‑> int
val elements : t ‑> elt list
val min_elt : t ‑> elt
val min_elt_opt : t ‑> elt option
val max_elt : t ‑> elt
val max_elt_opt : t ‑> elt option
val choose : t ‑> elt
val choose_opt : t ‑> elt option
val split : elt ‑> t ‑> t * bool * t
val find : elt ‑> t ‑> elt
val find_opt : elt ‑> t ‑> elt option
val find_first : (elt ‑> bool) ‑> t ‑> elt
val find_first_opt : (elt ‑> bool) ‑> t ‑> elt option
val find_last : (elt ‑> bool) ‑> t ‑> elt
val find_last_opt : (elt ‑> bool) ‑> t ‑> elt option
val of_list : elt list ‑> t
val of_seq : elt sequence ‑> t
val to_seq : t ‑> elt sequence
val to_list : t ‑> elt list
val of_list : elt list ‑> t
\ No newline at end of file diff --git a/1.0/sequence/SequenceLabels/index.html b/1.0/sequence/SequenceLabels/index.html new file mode 100644 index 0000000..5e81382 --- /dev/null +++ b/1.0/sequence/SequenceLabels/index.html @@ -0,0 +1,103 @@ + +SequenceLabels (sequence.SequenceLabels)

Module SequenceLabels

Simple and Efficient Iterators

Version of Sequence with labels

type +'a t = ('a ‑> unit) ‑> unit

A sequence of values of type 'a. If you give it a function 'a -> unit +it will be applied to every element of the sequence successively.

type +'a sequence = 'a t

NOTE Type ('a, 'b) t2 = ('a -> 'b -> unit) -> unit +has been removed and subsumed by ('a * 'b) t

type 'a equal = 'a ‑> 'a ‑> bool
type 'a hash = 'a ‑> int

Build a sequence

val from_iter : (('a ‑> unit) ‑> unit) ‑> 'a t

Build a sequence from a iter function

val from_fun : (unit ‑> 'a option) ‑> 'a t

Call the function repeatedly until it returns None. This +sequence is transient, use persistent if needed!

val empty : 'a t

Empty sequence. It contains no element.

val singleton : 'a ‑> 'a t

Singleton sequence, with exactly one element.

val doubleton : 'a ‑> 'a ‑> 'a t

Sequence with exactly two elements

val init : f:(int ‑> 'a) ‑> 'a t

init f is the infinite sequence f 0; f 1; f 2; ….

  • Since: 0.9
val cons : 'a ‑> 'a t ‑> 'a t

cons x l yields x, then yields from l. +Same as append (singleton x) l

val snoc : 'a t ‑> 'a ‑> 'a t

Same as cons but yields the element after iterating on l

val return : 'a ‑> 'a t

Synonym to singleton

val pure : 'a ‑> 'a t

Synonym to singleton

val repeat : 'a ‑> 'a t

Infinite sequence of the same element. You may want to look +at take and the likes if you iterate on it.

val iterate : ('a ‑> 'a) ‑> 'a ‑> 'a t

iterate f x is the infinite sequence x, f(x), f(f(x)), ...

val forever : (unit ‑> 'b) ‑> 'b t

Sequence that calls the given function to produce elements. +The sequence may be transient (depending on the function), and definitely +is infinite. You may want to use take and persistent.

val cycle : 'a t ‑> 'a t

Cycle forever through the given sequence. Assume the given sequence can +be traversed any amount of times (not transient). This yields an +infinite sequence, you should use something like take not to loop +forever.

Consume a sequence

val iter : f:('a ‑> unit) ‑> 'a t ‑> unit

Consume the sequence, passing all its arguments to the function. +Basically iter f seq is just seq f.

val iteri : f:(int ‑> 'a ‑> unit) ‑> 'a t ‑> unit

Iterate on elements and their index in the sequence

val fold : f:('a ‑> 'b ‑> 'a) ‑> init:'a ‑> 'b t ‑> 'a

Fold over elements of the sequence, consuming it

val foldi : f:('a ‑> int ‑> 'b ‑> 'a) ‑> init:'a ‑> 'b t ‑> 'a

Fold over elements of the sequence and their index, consuming it

val fold_map : f:('acc ‑> 'a ‑> 'acc * 'b) ‑> init:'acc ‑> 'a t ‑> 'b t

fold_map f acc l is like map, but it carries some state as in +fold. The state is not returned, it is just used to thread some +information to the map function.

  • Since: 0.9
val fold_filter_map : f:('acc ‑> 'a ‑> 'acc * 'b option) ‑> init:'acc ‑> 'a t ‑> 'b t

fold_filter_map f acc l is a fold_map-like function, but the +function can choose to skip an element by retuning None.

  • Since: 0.9
val map : f:('a ‑> 'b) ‑> 'a t ‑> 'b t

Map objects of the sequence into other elements, lazily

val mapi : f:(int ‑> 'a ‑> 'b) ‑> 'a t ‑> 'b t

Map objects, along with their index in the sequence

val map_by_2 : f:('a ‑> 'a ‑> 'a) ‑> 'a t ‑> 'a t

Map objects two by two. lazily. +The last element is kept in the sequence if the count is odd.

  • Since: 0.7
val for_all : f:('a ‑> bool) ‑> 'a t ‑> bool

Do all elements satisfy the predicate?

val exists : f:('a ‑> bool) ‑> 'a t ‑> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a ‑> 'a ‑> bool) ‑> x:'a ‑> 'a t ‑> bool

Is the value a member of the sequence?

  • Parameter eq: the equality predicate to use (default (=))
  • Since: 0.5
val find : ('a ‑> 'b option) ‑> 'a t ‑> 'b option

Find the first element on which the function doesn't return None

  • Since: 0.5
val find_map : f:('a ‑> 'b option) ‑> 'a t ‑> 'b option

Alias to find

  • Since: 0.10
val findi : f:(int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b option

Indexed version of find

  • Since: 0.9
val find_mapi : f:(int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b option

Alias to findi

  • Since: 0.10
val find_pred : f:('a ‑> bool) ‑> 'a t ‑> 'a option

find_pred p l finds the first element of l that satisfies p, +or returns None if no element satisfies p

  • Since: 0.9
val find_pred_exn : f:('a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of find_pred

  • Raises Not_found: if no such element is found
  • Since: 0.9
val length : 'a t ‑> int

How long is the sequence? Forces the sequence.

val is_empty : 'a t ‑> bool

Is the sequence empty? Forces the sequence.

Transform a sequence

val filter : f:('a ‑> bool) ‑> 'a t ‑> 'a t

Filter on elements of the sequence

val append : 'a t ‑> 'a t ‑> 'a t

Append two sequences. Iterating on the result is like iterating +on the first, then on the second.

val append_l : 'a t list ‑> 'a t

Append sequences. Iterating on the result is like iterating +on the each sequence of the list in order.

  • Since: 0.11
val concat : 'a t t ‑> 'a t

Concatenate a sequence of sequences into one sequence.

val flatten : 'a t t ‑> 'a t

Alias for concat

val flat_map : f:('a ‑> 'b t) ‑> 'a t ‑> 'b t

Alias to flatMap with a more explicit name

val flat_map_l : f:('a ‑> 'b list) ‑> 'a t ‑> 'b t

Convenience function combining flat_map and of_list

  • Since: 0.9
val filter_map : f:('a ‑> 'b option) ‑> 'a t ‑> 'b t

Alias to fmap with a more explicit name

val filter_mapi : f:(int ‑> 'a ‑> 'b option) ‑> 'a t ‑> 'b t

Map with indices, and only keep non-None elements

  • Since: 0.11
val seq_list : 'a t list ‑> 'a list t

seq_list l returns all the ways to pick one element in each sub-sequence +in l. Assumes the sub-sequences can be iterated on several times.

  • Since: 0.11
val seq_list_map : f:('a ‑> 'b t) ‑> 'a list ‑> 'b list t

seq_list_map f l maps f over every element of l, +then calls seq_list

  • Since: 0.11
val filter_count : f:('a ‑> bool) ‑> 'a t ‑> int

Count how many elements satisfy the given predicate

  • Since: 1.0
val intersperse : x:'a ‑> 'a t ‑> 'a t

Insert the single element between every element of the sequence

val keep_some : 'a option t ‑> 'a t

filter_some l retains only elements of the form Some x. +Same as filter_map (fun x->x)

  • Since: 1.0
val keep_ok : ('a_) Result.result t ‑> 'a t

keep_ok l retains only elements of the form Ok x.

  • Since: 1.0
val keep_error : (_'e) Result.result t ‑> 'e t

keep_error l retains only elements of the form Error x.

  • Since: 1.0

Caching

val persistent : 'a t ‑> 'a t

Iterate on the sequence, storing elements in an efficient internal structure.. +The resulting sequence can be iterated on as many times as needed. +Note: calling persistent on an already persistent sequence +will still make a new copy of the sequence!

val persistent_lazy : 'a t ‑> 'a t

Lazy version of persistent. When calling persistent_lazy s, +a new sequence s' is immediately returned (without actually consuming +s) in constant time; the first time s' is iterated on, +it also consumes s and caches its content into a inner data +structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal +is interrupted prematurely (take, etc.) then s' will not be +memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t

Sort the sequence. Eager, O(n) ram and O(n ln(n)) time. +It iterates on elements of the argument sequence immediately, +before it sorts them.

val sort_uniq : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> 'a t

Sort the sequence and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a ‑> 'a ‑> int) ‑> 'a t ‑> bool

Checks whether the sequence is sorted. Eager, same as sort.

  • Since: 0.9
val group_succ_by : ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a list t

Group equal consecutive elements. +Formerly synonym to group.

  • Since: 0.6
val group_by : ?⁠hash:('a ‑> int) ‑> ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a list t

Group equal elements, disregarding their order of appearance. +The result sequence is traversable as many times as required. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.6
val count : ?⁠hash:('a ‑> int) ‑> ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. +Similar to group_by seq |> map (fun l->List.hd l, List.length l)

  • Since: 0.10
val uniq : ?⁠eq:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a t

Remove consecutive duplicate elements. Basically this is +like fun seq -> map List.hd (group seq).

val product : 'a t ‑> 'b t ‑> ('a * 'b) t

Cartesian product of the sequences. When calling product a b, +the caller MUST ensure that b can be traversed as many times +as required (several times), possibly by calling persistent on it +beforehand.

val diagonal_l : 'a list ‑> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will +return the sequence of all List.nth i l, List.nth j l if i < j.

  • Since: 0.9
val diagonal : 'a t ‑> ('a * 'a) t

All pairs of distinct positions of the sequence. +Iterates only once on the sequence, which must be finite.

  • Since: 0.9
val join : join_row:('a ‑> 'b ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join ~join_row a b combines every element of a with every +element of b using join_row. If join_row returns None, then +the two elements do not combine. Assume that b allows for multiple +iterations.

val join_by : ?⁠eq:'key equal ‑> ?⁠hash:'key hash ‑> ('a ‑> 'key) ‑> ('b ‑> 'key) ‑> merge:('key ‑> 'a ‑> 'b ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join key1 key2 ~merge is a binary operation +that takes two sequences a and b, projects their +elements resp. with key1 and key2, and combine +values (x,y) from (a,b) with the same key +using merge. If merge returns None, the combination +of values is discarded. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val join_all_by : ?⁠eq:'key equal ‑> ?⁠hash:'key hash ‑> ('a ‑> 'key) ‑> ('b ‑> 'key) ‑> merge:('key ‑> 'a list ‑> 'b list ‑> 'c option) ‑> 'a t ‑> 'b t ‑> 'c t

join_all_by key1 key2 ~merge is a binary operation +that takes two sequences a and b, projects their +elements resp. with key1 and key2, and, for each key k +occurring in at least one of them: +

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination +of values is discarded, otherwise it returns Some c +and c is inserted in the result.
  • Since: 0.10
val group_join_by : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> ('b ‑> 'a) ‑> 'a t ‑> 'b t ‑> ('a * 'b list) t

group_join_by key2 associates to every element x of +the first sequence, all the elements y of the second +sequence such that eq x (key y). Elements of the first +sequences without corresponding values in the second one +are mapped to [] +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val inter : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Intersection of two collections. Each element will occur at most once +in the result. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val union : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Union of two collections. Each element will occur at most once +in the result. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val diff : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> 'a t

Set difference. Eager.

  • Since: 0.10
val subset : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> 'a t ‑> 'a t ‑> bool

subset a b returns true if all elements of a belong to b. Eager. +precondition: for any x and y, if eq x y then hash x=hash y must hold.

  • Since: 0.10
val unfoldr : ('b ‑> ('a * 'b) option) ‑> 'b ‑> 'a t

unfoldr f b will apply f to b. If it +yields Some (x,b') then x is returned +and unfoldr recurses with b'.

val scan : ('b ‑> 'a ‑> 'b) ‑> 'b ‑> 'a t ‑> 'b t

Sequence of intermediate results

val max : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a option

Max element of the sequence, using the given comparison function.

  • Returns None if the sequence is empty, Some m where m is the maximal +element otherwise
val max_exn : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of max

  • Raises Not_found: if the sequence is empty
  • Since: 0.10
val min : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a option

Min element of the sequence, using the given comparison function. +see max for more details.

val min_exn : ?⁠lt:('a ‑> 'a ‑> bool) ‑> 'a t ‑> 'a

Unsafe version of min

  • Raises Not_found: if the sequence is empty
  • Since: 0.10
val sum : int t ‑> int

Sum of elements

  • Since: 0.11
val sumf : float t ‑> float

Sum of elements, using Kahan summation

  • Since: 0.11
val head : 'a t ‑> 'a option

First element, if any, otherwise None

  • Since: 0.5.1
val head_exn : 'a t ‑> 'a

First element, if any, fails

  • Raises Invalid_argument: if the sequence is empty
  • Since: 0.5.1
val take : int ‑> 'a t ‑> 'a t

Take at most n elements from the sequence. Works on infinite +sequences.

val take_while : f:('a ‑> bool) ‑> 'a t ‑> 'a t

Take elements while they satisfy the predicate, then stops iterating. +Will work on an infinite sequence s if the predicate is false for at +least one element of s.

val fold_while : f:('a ‑> 'b ‑> 'a * [ `Stop | `Continue ]) ‑> init:'a ‑> 'b t ‑> 'a

Folds over elements of the sequence, stopping early if the accumulator +returns ('a, `Stop)

  • Since: 0.5.5
val drop : int ‑> 'a t ‑> 'a t

Drop the n first elements of the sequence. Lazy.

val drop_while : f:('a ‑> bool) ‑> 'a t ‑> 'a t

Predicate version of drop

val rev : 'a t ‑> 'a t

Reverse the sequence. O(n) memory and time, needs the +sequence to be finite. The result is persistent and does +not depend on the input being repeatable.

val zip_i : 'a t ‑> (int * 'a) t
val fold2 : f:('c ‑> 'a ‑> 'b ‑> 'c) ‑> init:'c ‑> ('a * 'b) t ‑> 'c
val iter2 : f:('a ‑> 'b ‑> unit) ‑> ('a * 'b) t ‑> unit
val map2 : f:('a ‑> 'b ‑> 'c) ‑> ('a * 'b) t ‑> 'c t
val map2_2 : f:('a ‑> 'b ‑> 'c) ‑> ('a ‑> 'b ‑> 'd) ‑> ('a * 'b) t ‑> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Basic data structures converters

val to_list : 'a t ‑> 'a list

Convert the sequence into a list. Preserves order of elements. +This function is tail-recursive, but consumes 2*n memory. +If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t ‑> 'a list

Get the list of the reversed sequence (more efficient than to_list)

val of_list : 'a list ‑> 'a t
val on_list : ('a t ‑> 'b t) ‑> 'a list ‑> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • Since: 0.5.2
val pair_with_idx : 'a t ‑> (int * 'a) t

Similar to zip_i but returns a normal sequence of tuples

  • Since: 0.11
val to_opt : 'a t ‑> 'a option

Alias to head

  • Since: 0.5.1
val to_array : 'a t ‑> 'a array

Convert to an array. Currently not very efficient because +an intermediate list is used.

val of_array : 'a array ‑> 'a t
val of_array_i : 'a array ‑> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array ‑> int ‑> int ‑> 'a t

array_slice a i j Sequence of elements whose indexes range +from i to j

val of_opt : 'a option ‑> 'a t

Iterate on 0 or 1 values.

  • Since: 0.5.1
val of_stream : 'a Stream.t ‑> 'a t

Sequence of elements of a stream (usable only once)

val to_stream : 'a t ‑> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t ‑> 'a t ‑> unit

Push elements of the sequence on the stack

val of_stack : 'a Stack.t ‑> 'a t

Sequence of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t ‑> 'a t ‑> unit

Push elements of the sequence into the queue

val of_queue : 'a Queue.t ‑> 'a t

Sequence of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t ‑> ('a * 'b) t ‑> unit

Add elements of the sequence to the hashtable, with +Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t ‑> ('a * 'b) t ‑> unit

Add elements of the sequence to the hashtable, with +Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t ‑> ('a'b) Hashtbl.t

Build a hashtable from a sequence of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t ‑> ('a * 'b) t

Sequence of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t ‑> 'a t
val hashtbl_values : ('a'b) Hashtbl.t ‑> 'b t
val of_str : string ‑> char t
val to_str : char t ‑> string
val concat_str : string t ‑> string

Concatenate strings together, eagerly. +Also see intersperse to add a separator.

  • Since: 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on +a transient iterator

val of_in_channel : Pervasives.in_channel ‑> char t

Iterates on characters of the input (can block when one +iterates over the sequence). If you need to iterate +several times on this sequence, use persistent.

  • Raises OneShotSequence: when used more than once.
val to_buffer : char t ‑> Buffer.t ‑> unit

Copy content of the sequence into the buffer

val int_range : start:int ‑> stop:int ‑> int t
val int_range_dec : start:int ‑> stop:int ‑> int t
val int_range_by : step:int ‑> start:int ‑> stop:int ‑> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, +where the difference between successive elements is step. +use a negative step for a decreasing sequence.

  • Since: 0.9
  • Raises Invalid_argument: if step=0
val bools : bool t

Iterates on true and false

  • Since: 0.9
val of_set : (module Set.S with type elt = 'a and type t = 'b) ‑> 'b ‑> 'a t

Convert the given set to a sequence. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) ‑> 'a t ‑> 'b

Convert the sequence to a set, given the proper set module

type 'a gen = unit ‑> 'a option
type 'a klist = unit ‑> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen ‑> 'a t

Traverse eagerly the generator and build a sequence from it

val to_gen : 'a t ‑> 'a gen

Make the sequence persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist ‑> 'a t

Iterate on the lazy list

val to_klist : 'a t ‑> 'a klist

Make the sequence persistent and then iterate on it. Eager.

Functorial conversions between sets and sequences

module Set : sig ... end

Conversion between maps and sequences.

module Map : sig ... end

Infinite sequences of random values

val random_int : int ‑> int t

Infinite sequence of random integers between 0 and +the given higher bound (see Random.int)

val random_bool : bool t

Infinite sequence of random bool values

val random_float : float ‑> float t
val random_array : 'a array ‑> 'a t

Sequence of choices of an element in the array

val random_list : 'a list ‑> 'a t

Infinite sequence of random elements of the list. Basically the +same as random_array.

val shuffle : 'a t ‑> 'a t

shuffle seq returns a perfect shuffle of seq. +Uses O(length seq) memory and time. Eager.

  • Since: 0.7
val shuffle_buffer : n:int ‑> 'a t ‑> 'a t

shuffle_buffer n seq returns a sequence of element of seq in random +order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the sequence are consumed immediately. The +rest is consumed lazily.

  • Since: 0.7

Sampling

val sample : n:int ‑> 'a t ‑> 'a array

sample n seq returns k samples of seq, with uniform probability. +It will consume the sequence and use O(n) memory.

It returns an array of size min (length seq) n.

  • Since: 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int ‑> int ‑> int t

a -- b is the range of integers from a to b, both included, +in increasing order. It will therefore be empty if a > b.

val (--^) : int ‑> int ‑> int t

a --^ b is the range of integers from b to a, both included, +in decreasing order (starts from a). +It will therefore be empty if a < b.

val (>>=) : 'a t ‑> ('a ‑> 'b t) ‑> 'b t

Monadic bind (infix version of flat_map

  • Since: 0.5
val (>|=) : 'a t ‑> ('a ‑> 'b) ‑> 'b t

Infix version of map

  • Since: 0.5
val (<*>) : ('a ‑> 'b) t ‑> 'a t ‑> 'b t

Applicative operator (product+application)

  • Since: 0.5
val (<+>) : 'a t ‑> 'a t ‑> 'a t

Concatenation of sequences

  • Since: 0.5

Pretty printing of sequences

val pp_seq : ?⁠sep:string ‑> (Format.formatter ‑> 'a ‑> unit) ‑> Format.formatter ‑> 'a t ‑> unit

Pretty print a sequence of 'a, using the given pretty printer +to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string ‑> (Buffer.t ‑> 'a ‑> unit) ‑> Buffer.t ‑> 'a t ‑> unit

Print into a buffer

val to_string : ?⁠sep:string ‑> ('a ‑> string) ‑> 'a t ‑> string

Print into a string

Basic IO

Very basic interface to manipulate files as sequence of chunks/lines. The +sequences take care of opening and closing files properly; every time +one iterates over a sequence, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

      Sequence.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

      Sequence.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

      Sequence.IO.lines "a" |> Sequence.to_list
module IO : sig ... end
\ No newline at end of file diff --git a/1.0/sequence/index.html b/1.0/sequence/index.html new file mode 100644 index 0000000..e429088 --- /dev/null +++ b/1.0/sequence/index.html @@ -0,0 +1,3 @@ + +sequence-generated (sequence.sequence-generated)

Library sequence

+This library exposes the following toplevel modules:

Sequence
SequenceLabels

.

\ No newline at end of file diff --git a/1.1/highlight.pack.js b/1.1/highlight.pack.js new file mode 100644 index 0000000..40370e8 --- /dev/null +++ b/1.1/highlight.pack.js @@ -0,0 +1,2 @@ +/*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */ +!function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/g,"&").replace(//g,">")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r>n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!==r[0].offset?e[0].offset"}function u(e){s+=""}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&&g.length&&g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&&!e.cached_variants&&(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&&[o(e)]||[e]}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),null==a.r&&(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a>t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&&!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r>0&&(B+=t.r),e&&(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&&(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&&(k=n));do E.cN&&(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&&(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&&(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&&-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&&"\n"===e?"
":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(//g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&&(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&&r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,C="
",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("ocaml",function(e){return{aliases:["ml"],k:{keyword:"and as assert asr begin class constraint do done downto else end exception external for fun function functor if in include inherit! inherit initializer land lazy let lor lsl lsr lxor match method!|10 method mod module mutable new object of open! open or private rec sig struct then to try type val! val virtual when while with parser value",built_in:"array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 string unit in_channel out_channel ref",literal:"true false"},i:/\/\/|>>/,l:"[a-z_]\\w*!?",c:[{cN:"literal",b:"\\[(\\|\\|)?\\]|\\(\\)",r:0},e.C("\\(\\*","\\*\\)",{c:["self"]}),{cN:"symbol",b:"'[A-Za-z_](?!')[\\w']*"},{cN:"type",b:"`[A-Z][\\w']*"},{cN:"type",b:"\\b[A-Z][\\w']*",r:0},{b:"[a-z_]\\w*'[\\w']*",r:0},e.inherit(e.ASM,{cN:"string",r:0}),e.inherit(e.QSM,{i:null}),{cN:"number",b:"\\b(0[xX][a-fA-F0-9_]+[Lln]?|0[oO][0-7_]+[Lln]?|0[bB][01_]+[Lln]?|[0-9][0-9_]*([Lln]|(\\.[0-9_]*)?([eE][-+]?[0-9_]+)?)?)",r:0},{b:/[-=]>/}]}}); \ No newline at end of file diff --git a/1.1/index.html b/1.1/index.html new file mode 100644 index 0000000..7763a5d --- /dev/null +++ b/1.1/index.html @@ -0,0 +1,19 @@ + + + + index + + + + + +
+
+

OCaml package documentation

+
    +
  1. sequence 1.1
  2. +
+
+
+ + \ No newline at end of file diff --git a/1.1/odoc.css b/1.1/odoc.css new file mode 100644 index 0000000..c86c417 --- /dev/null +++ b/1.1/odoc.css @@ -0,0 +1,764 @@ +@charset "UTF-8"; +/* Copyright (c) 2016 The odoc contributors. All rights reserved. + Distributed under the ISC license, see terms at the end of the file. + odoc 1.4.0 */ + +/* Fonts */ +@import url('https://fonts.googleapis.com/css?family=Fira+Mono:400,500'); +@import url('https://fonts.googleapis.com/css?family=Noticia+Text:400,400i,700'); +@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,400i,500,500i,600,600i,700,700i'); + + +/* Reset a few things. */ + +html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: inherit; + font: inherit; + line-height: inherit; + vertical-align: baseline; + text-align: inherit; + color: inherit; + background: transparent; +} + +table { + border-collapse: collapse; + border-spacing: 0; +} + +*, *:before, *:after { + box-sizing: border-box; +} + +html { + font-size: 15px; +} + +body { + font-family: "Fira Sans", Helvetica, Arial, sans-serif; + text-align: left; + color: #333; + background: #FFFFFF; +} + +.content { + max-width: 90ex; + margin-left: calc(10vw + 20ex); + margin-right: 4ex; + margin-top: 20px; + margin-bottom: 50px; + font-family: "Noticia Text", Georgia, serif; + line-height: 1.5; +} + +.content>header { + margin-bottom: 30px; +} + +.content>header nav { + font-family: "Fira Sans", Helvetica, Arial, sans-serif; +} + +/* Basic markup elements */ + +b, strong { + font-weight: 500; +} + +i, em { + font-style: italic; +} + +sup { + vertical-align: super; +} + +sub { + vertical-align: sub; +} + +sup, sub { + font-size: 12px; + line-height: 0; + margin-left: 0.2ex; +} + +pre { + margin-top: 0.8em; + margin-bottom: 1.2em; +} + +p, ul, ol { + margin-top: 0.5em; + margin-bottom: 1em; +} +ul, ol { + list-style-position: outside +} + +ul>li { + margin-left: 22px; +} + +ol>li { + margin-left: 27.2px; +} + +li>*:first-child { + margin-top: 0 +} + +/* Text alignements, this should be forbidden. */ + +.left { + text-align: left; +} + +.right { + text-align: right; +} + +.center { + text-align: center; +} + +/* Links and anchors */ + +a { + text-decoration: none; + color: #2C5CBD; +} + +a:hover { + box-shadow: 0 1px 0 0 #2C5CBD; +} + +/* Linked highlight */ +*:target { + background-color: rgba(187,239,253,0.3) !important; + box-shadow: 0 0px 0 1px rgba(187,239,253,0.8) !important; + border-radius: 1px; +} + +*:hover>a.anchor { + visibility: visible; +} + +a.anchor:before { + content: "#" +} + +a.anchor:hover { + box-shadow: none; + text-decoration: none; + color: #555; +} + +a.anchor { + visibility: hidden; + position: absolute; + /* top: 0px; */ + /* margin-left: -3ex; */ + margin-left: -1.3em; + font-weight: normal; + font-style: normal; + padding-right: 0.4em; + padding-left: 0.4em; + /* To remain selectable */ + color: #d5d5d5; +} + +.spec > a.anchor { + margin-left: -2.3em; + padding-right: 0.9em; +} + +.xref-unresolved { + color: #2C5CBD; +} +.xref-unresolved:hover { + box-shadow: 0 1px 0 0 #CC6666; +} + +/* Section and document divisions. + Until at least 4.03 many of the modules of the stdlib start at .h7, + we restart the sequence there like h2 */ + +h1, h2, h3, h4, h5, h6, .h7, .h8, .h9, .h10 { + font-family: "Fira Sans", Helvetica, Arial, sans-serif; + font-weight: 400; + margin: 0.5em 0 0.5em 0; + padding-top: 0.1em; + line-height: 1.2; + overflow-wrap: break-word; +} + +h1 { + font-weight: 500; + font-size: 2.441em; + margin-top: 1.214em; +} + +h1 { + font-weight: 500; + font-size: 1.953em; + box-shadow: 0 1px 0 0 #ddd; +} + +h2 { + font-size: 1.563em; +} + +h3 { + font-size: 1.25em; +} + +small, .font_small { + font-size: 0.8em; +} + +h1 code, h1 tt { + font-size: inherit; + font-weight: inherit; +} + +h2 code, h2 tt { + font-size: inherit; + font-weight: inherit; +} + +h3 code, h3 tt { + font-size: inherit; + font-weight: inherit; +} + +h3 code, h3 tt { + font-size: inherit; + font-weight: inherit; +} + +h4 { + font-size: 1.12em; +} + + +/* Preformatted and code */ + +tt, code, pre { + font-family: "Fira Mono", courier; + font-weight: 400; +} + +pre { + padding: 0.1em; + border: 1px solid #eee; + border-radius: 5px; + overflow-x: auto; +} + +p code, li code { + background-color: #f6f8fa; + color: #0d2b3e; + border-radius: 3px; + padding: 0 0.3ex; +} + +p a > code { + color: #2C5CBD; +} + +/* Code blocks (e.g. Examples) */ + +pre code { + font-size: 0.893rem; +} + +/* Code lexemes */ + +.keyword { + font-weight: 500; +} + +/* Module member specification */ + +.spec:not(.include), .spec.include details summary { + background-color: #f6f8fa; + border-radius: 3px; + border-left: 4px solid #5c9cf5; + border-right: 5px solid transparent; + padding: 0.35em 0.5em; +} + +.spec.include details summary:hover { + background-color: #ebeff2; +} + +dl, div.spec, .doc, aside { + margin-bottom: 20px; +} + +dl > dd { + padding: 0.5em; +} + +dd> :first-child { + margin-top: 0; +} + +dl:last-child, dd> :last-child, aside:last-child, article:last-child { + margin-bottom: 0; +} + +dt+dt { + margin-top: 15px; +} + +section+section, section > header + dl { + margin-top: 25px; +} + +.spec.type .variant { + margin-left: 2ch; +} +.spec.type .variant p { + margin: 0; + font-style: italic; +} +.spec.type .record { + margin-left: 2ch; +} +.spec.type .record p { + margin: 0; + font-style: italic; +} + +div.def { + margin-top: 0; + text-indent: -2ex; + padding-left: 2ex; +} + +div.def+div.doc { + margin-left: 1ex; + margin-top: 2.5px +} + +div.doc>*:first-child { + margin-top: 0; +} + +/* The elements other than heading should be wrapped in
diff --git a/1.2/iter/Iter/index.html b/1.2/iter/Iter/index.html index 9a618a4..f3f468f 100644 --- a/1.2/iter/Iter/index.html +++ b/1.2/iter/Iter/index.html @@ -1,2 +1,2 @@ -Iter (iter.Iter)

Module Iter

Simple and Efficient Iterators

type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
NEXT_RELEASE
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : (int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

Consumption

val iter : ('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : ('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : ('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : ('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : ('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : ('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : ('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : ('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : ('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

Monadic bind. Intuitively, it applies the function to every element of the initial iterator, and calls concat. Formerly flatMap

since
0.5
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : ('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : ('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

since
0.5
val filter_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : ('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : 'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Linear time. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l) precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Set-like

val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Arithmetic

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11

List-like

val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : ('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : ('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs

Pair iterators

val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a * 'b) t -> 'c
val iter2 : ('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : ('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> int -> int -> int t

int_range_by ~step i j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.7
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO : sig ... end
\ No newline at end of file +Iter (iter.Iter)

Module Iter

Simple and Efficient Iterators

type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
1.2
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : (int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

Consumption

val iter : ('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : ('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : ('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : ('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : ('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : ('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : ('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : ('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : ('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

Monadic bind. Intuitively, it applies the function to every element of the initial iterator, and calls concat. Formerly flatMap

since
0.5
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : ('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : ('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

since
0.5
val filter_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : ('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : 'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Linear time. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l) precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Set-like

val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Arithmetic

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11

List-like

val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : ('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : ('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs

Pair iterators

val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a * 'b) t -> 'c
val iter2 : ('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : ('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> int -> int -> int t

int_range_by ~step i j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.7
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO : sig ... end
\ No newline at end of file diff --git a/1.2/iter/IterLabels/index.html b/1.2/iter/IterLabels/index.html index 3bc68f4..cb09345 100644 --- a/1.2/iter/IterLabels/index.html +++ b/1.2/iter/IterLabels/index.html @@ -1,2 +1,2 @@ -IterLabels (iter.IterLabels)

Module IterLabels

Simple and Efficient Iterators

Version of Iterator with labels

since
0.5.5
type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
NEXT_RELEASE
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : f:(int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

Consumption

val iter : f:('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : f:(int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : f:('acc -> 'a -> 'acc * 'b) -> init:'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : f:('acc -> 'a -> 'acc * 'b option) -> init:'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : f:('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : f:('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : f:('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : f:('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> x:'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : f:('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : f:('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : f:('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : f:('a -> 'b t) -> 'a t -> 'b t

Alias to flatMap with a more explicit name

val flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : f:('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

val filter_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : f:('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : x:'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l)

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of the iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11
val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : f:('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : f:('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs
val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a * 'b) t -> 'c
val iter2 : f:('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : f:('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : f:('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> start:int -> stop:int -> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

since
0.9
raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.9
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : n:int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : n:int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO : sig ... end
\ No newline at end of file +IterLabels (iter.IterLabels)

Module IterLabels

Simple and Efficient Iterators

Version of Iterator with labels

since
0.5.5
type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
1.2
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : f:(int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

Consumption

val iter : f:('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : f:(int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : f:('acc -> 'a -> 'acc * 'b) -> init:'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : f:('acc -> 'a -> 'acc * 'b option) -> init:'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : f:('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : f:('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : f:('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : f:('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> x:'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : f:('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : f:('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : f:('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : f:('a -> 'b t) -> 'a t -> 'b t

Alias to flatMap with a more explicit name

val flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : f:('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

val filter_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : f:('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : x:'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l)

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of the iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11
val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : f:('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : f:('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs
val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a * 'b) t -> 'c
val iter2 : f:('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : f:('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : f:('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> start:int -> stop:int -> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

since
0.9
raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.9
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : n:int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : n:int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO : sig ... end
\ No newline at end of file diff --git a/1.2/odoc.css b/1.2/odoc.css index 637fa45..c86c417 100644 --- a/1.2/odoc.css +++ b/1.2/odoc.css @@ -1,7 +1,7 @@ @charset "UTF-8"; /* Copyright (c) 2016 The odoc contributors. All rights reserved. Distributed under the ISC license, see terms at the end of the file. - odoc v1.1.1-949-gd6999cc74 */ + odoc 1.4.0 */ /* Fonts */ @import url('https://fonts.googleapis.com/css?family=Fira+Mono:400,500'); diff --git a/1.2/sequence/Sequence/index.html b/1.2/sequence/Sequence/index.html deleted file mode 100644 index f4fde31..0000000 --- a/1.2/sequence/Sequence/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Sequence (sequence.Sequence)

Module Sequence

include Iter
type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
NEXT_RELEASE
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : (int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

Consumption

val iter : ('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : ('a -> int -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : ('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : ('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : ('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : ('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : ('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : ('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : ('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : ('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : ('a -> 'b t) -> 'a t -> 'b t

Monadic bind. Intuitively, it applies the function to every element of the initial iterator, and calls concat. Formerly flatMap

since
0.5
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : ('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : ('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

since
0.5
val filter_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : ('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : 'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Linear time. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l) precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Set-like

val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10

Arithmetic

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11

List-like

val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : ('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : ('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs

Pair iterators

val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a * 'b) t -> 'c
val iter2 : ('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : ('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : ('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> int -> int -> int t

int_range_by ~step i j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.7
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set = Iter.Set

Maps

module Map = Iter.Map

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix = Iter.Infix
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO = Iter.IO
type 'a sequence = 'a iter
\ No newline at end of file diff --git a/1.2/sequence/SequenceLabels/index.html b/1.2/sequence/SequenceLabels/index.html deleted file mode 100644 index a646222..0000000 --- a/1.2/sequence/SequenceLabels/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -SequenceLabels (sequence.SequenceLabels)

Module SequenceLabels

include IterLabels
type +'a t = ('a -> unit) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : (('a -> unit) -> unit) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : (f:('a -> unit) -> unit) -> 'a t

Build an iterator from a labelled iter function

since
NEXT_RELEASE
val from_fun : (unit -> 'a option) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : f:(int -> 'a) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

since
0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ('a -> 'a) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : (unit -> 'b) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

Consumption

val iter : f:('a -> unit) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : f:(int -> 'a -> unit) -> 'a t -> unit

Iterate on elements and their index in the iterator

val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : f:('acc -> 'a -> 'acc * 'b) -> init:'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

since
0.9
val fold_filter_map : f:('acc -> 'a -> 'acc * 'b option) -> init:'acc -> 'a t -> 'b t

fold_filter_map f acc l is a fold_map-like function, but the function can choose to skip an element by retuning None.

since
0.9
val map : f:('a -> 'b) -> 'a t -> 'b t

Map objects of the iterator into other elements, lazily

val mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b t

Map objects, along with their index in the iterator

val map_by_2 : f:('a -> 'a -> 'a) -> 'a t -> 'a t

Map objects two by two. lazily. The last element is kept in the iterator if the count is odd.

since
0.7
val for_all : f:('a -> bool) -> 'a t -> bool

Do all elements satisfy the predicate?

val exists : f:('a -> bool) -> 'a t -> bool

Exists there some element satisfying the predicate?

val mem : ?⁠eq:('a -> 'a -> bool) -> x:'a -> 'a t -> bool

Is the value a member of the iterator?

parameter eq

the equality predicate to use (default (=))

since
0.5
val find : ('a -> 'b option) -> 'a t -> 'b option

Find the first element on which the function doesn't return None

since
0.5
val find_map : f:('a -> 'b option) -> 'a t -> 'b option

Alias to find

since
0.10
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Indexed version of find

since
0.9
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option

Alias to findi

since
0.10
val find_pred : f:('a -> bool) -> 'a t -> 'a option

find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p

since
0.9
val find_pred_exn : f:('a -> bool) -> 'a t -> 'a

Unsafe version of find_pred

raises Not_found

if no such element is found

since
0.9
val length : 'a t -> int

How long is the iterator? Forces the iterator.

val is_empty : 'a t -> bool

Is the iterator empty? Forces the iterator.

Transformation

val filter : f:('a -> bool) -> 'a t -> 'a t

Filter on elements of the iterator

val append : 'a t -> 'a t -> 'a t

Append two iterators. Iterating on the result is like iterating on the first, then on the second.

val append_l : 'a t list -> 'a t

Append iterators. Iterating on the result is like iterating on the each iterator of the list in order.

since
0.11
val concat : 'a t t -> 'a t

Concatenate an iterator of iterators into one iterator.

val flatten : 'a t t -> 'a t

Alias for concat

val flat_map : f:('a -> 'b t) -> 'a t -> 'b t

Alias to flatMap with a more explicit name

val flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t

Convenience function combining flat_map and of_list

since
0.9
val seq_list : 'a t list -> 'a list t

seq_list l returns all the ways to pick one element in each sub-iterator in l. Assumes the sub-iterators can be iterated on several times.

since
0.11
val seq_list_map : f:('a -> 'b t) -> 'a list -> 'b list t

seq_list_map f l maps f over every element of l, then calls seq_list

since
0.11
val filter_map : f:('a -> 'b option) -> 'a t -> 'b t

Map and only keep non-None elements Formerly fmap

val filter_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b t

Map with indices, and only keep non-None elements

since
0.11
val filter_count : f:('a -> bool) -> 'a t -> int

Count how many elements satisfy the given predicate

since
1.0
val intersperse : x:'a -> 'a t -> 'a t

Insert the single element between every element of the iterator

val keep_some : 'a option t -> 'a t

filter_some l retains only elements of the form Some x. Same as filter_map (fun x->x)

since
1.0
val keep_ok : ('a_) Result.result t -> 'a t

keep_ok l retains only elements of the form Ok x.

since
1.0
val keep_error : (_'e) Result.result t -> 'e t

keep_error l retains only elements of the form Error x.

since
1.0

Caching

val persistent : 'a t -> 'a t

Iterate on the iterator, storing elements in an efficient internal structure.. The resulting iterator can be iterated on as many times as needed. Note: calling persistent on an already persistent iterator will still make a new copy of the iterator!

val persistent_lazy : 'a t -> 'a t

Lazy version of persistent. When calling persistent_lazy s, a new iterator s' is immediately returned (without actually consuming s) in constant time; the first time s' is iterated on, it also consumes s and caches its content into a inner data structure that will back s' for future iterations.

warning: on the first traversal of s', if the traversal is interrupted prematurely (take, etc.) then s' will not be memorized, and the next call to s' will traverse s again.

Misc

val sort : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator. Eager, O(n) ram and O(n ln(n)) time. It iterates on elements of the argument iterator immediately, before it sorts them.

val sort_uniq : ?⁠cmp:('a -> 'a -> int) -> 'a t -> 'a t

Sort the iterator and remove duplicates. Eager, same as sort

val sorted : ?⁠cmp:('a -> 'a -> int) -> 'a t -> bool

Checks whether the iterator is sorted. Eager, same as sort.

since
0.9
val group_succ_by : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal consecutive elements. Formerly synonym to group.

since
0.6
val group_by : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a list t

Group equal elements, disregarding their order of appearance. The result iterator is traversable as many times as required. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.6
val count : ?⁠hash:('a -> int) -> ?⁠eq:('a -> 'a -> bool) -> 'a t -> ('a * int) t

Map each distinct element to its number of occurrences in the whole seq. Similar to group_by seq |> map (fun l->List.hd l, List.length l)

since
0.10
val uniq : ?⁠eq:('a -> 'a -> bool) -> 'a t -> 'a t

Remove consecutive duplicate elements. Basically this is like fun seq -> map List.hd (group seq).

val product : 'a t -> 'b t -> ('a * 'b) t

Cartesian product of the iterators. When calling product a b, the caller MUST ensure that b can be traversed as many times as required (several times), possibly by calling persistent on it beforehand.

val diagonal_l : 'a list -> ('a * 'a) t

All pairs of distinct positions of the list. diagonal l will return the iterator of all List.nth i l, List.nth j l if i < j.

since
0.9
val diagonal : 'a t -> ('a * 'a) t

All pairs of distinct positions of the iterator. Iterates only once on the iterator, which must be finite.

since
0.9
val join : join_row:('a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join ~join_row a b combines every element of a with every element of b using join_row. If join_row returns None, then the two elements do not combine. Assume that b allows for multiple iterations.

val join_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a -> 'b -> 'c option) -> 'a t -> 'b t -> 'c t

join key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and combine values (x,y) from (a,b) with the same key using merge. If merge returns None, the combination of values is discarded. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val join_all_by : ?⁠eq:'key equal -> ?⁠hash:'key hash -> ('a -> 'key) -> ('b -> 'key) -> merge:('key -> 'a list -> 'b list -> 'c option) -> 'a t -> 'b t -> 'c t

join_all_by key1 key2 ~merge is a binary operation that takes two iterators a and b, projects their elements resp. with key1 and key2, and, for each key k occurring in at least one of them:

  • compute the list l1 of elements of a that map to k
  • compute the list l2 of elements of b that map to k
  • call merge k l1 l2. If merge returns None, the combination of values is discarded, otherwise it returns Some c and c is inserted in the result.
since
0.10
val group_join_by : ?⁠eq:'a equal -> ?⁠hash:'a hash -> ('b -> 'a) -> 'a t -> 'b t -> ('a * 'b list) t

group_join_by key2 associates to every element x of the first iterator, all the elements y of the second iterator such that eq x (key y). Elements of the first iterators without corresponding values in the second one are mapped to [] precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val inter : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Intersection of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val union : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Union of two collections. Each element will occur at most once in the result. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val diff : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> 'a t

Set difference. Eager.

since
0.10
val subset : ?⁠eq:'a equal -> ?⁠hash:'a hash -> 'a t -> 'a t -> bool

subset a b returns true if all elements of a belong to b. Eager. precondition: for any x and y, if eq x y then hash x=hash y must hold.

since
0.10
val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

val max : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Max element of the iterator, using the given comparison function.

returns

None if the iterator is empty, Some m where m is the maximal element otherwise

val max_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of max

raises Not_found

if the iterator is empty

since
0.10
val min : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a option

Min element of the iterator, using the given comparison function. see max for more details.

val min_exn : ?⁠lt:('a -> 'a -> bool) -> 'a t -> 'a

Unsafe version of min

raises Not_found

if the iterator is empty

since
0.10
val sum : int t -> int

Sum of elements

since
0.11
val sumf : float t -> float

Sum of elements, using Kahan summation

since
0.11
val head : 'a t -> 'a option

First element, if any, otherwise None

since
0.5.1
val head_exn : 'a t -> 'a

First element, if any, fails

raises Invalid_argument

if the iterator is empty

since
0.5.1
val take : int -> 'a t -> 'a t

Take at most n elements from the iterator. Works on infinite iterators.

val take_while : f:('a -> bool) -> 'a t -> 'a t

Take elements while they satisfy the predicate, then stops iterating. Will work on an infinite iterator s if the predicate is false for at least one element of s.

val fold_while : f:('a -> 'b -> 'a * [ `Stop | `Continue ]) -> init:'a -> 'b t -> 'a

Folds over elements of the iterator, stopping early if the accumulator returns ('a, `Stop)

since
0.5.5
val drop : int -> 'a t -> 'a t

Drop the n first elements of the iterator. Lazy.

val drop_while : f:('a -> bool) -> 'a t -> 'a t

Predicate version of drop

val rev : 'a t -> 'a t

Reverse the iterator. O(n) memory and time, needs the iterator to be finite. The result is persistent and does not depend on the input being repeatable.

val zip_i : 'a t -> (int * 'a) t

Zip elements of the iterator with their index in the iterator.

since
1.0 Changed type to just give an iterator of pairs
val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a * 'b) t -> 'c
val iter2 : f:('a -> 'b -> unit) -> ('a * 'b) t -> unit
val map2 : f:('a -> 'b -> 'c) -> ('a * 'b) t -> 'c t
val map2_2 : f:('a -> 'b -> 'c) -> ('a -> 'b -> 'd) -> ('a * 'b) t -> ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

since
0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

since
0.11
val to_opt : 'a t -> 'a option

Alias to head

since
0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

since
0.5.1
val of_stream : 'a Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ('a'b) Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ('a'b) Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ('a'b) Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ('a'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

since
0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Pervasives.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

raises OneShotIterator

when used more than once.

val to_buffer : char t -> Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> start:int -> stop:int -> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

since
0.9
raises Invalid_argument

if step=0

val bools : bool t

Iterates on true and false

since
0.9
val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set = IterLabels.Set

Maps

module Map = IterLabels.Map

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

since
0.7
val shuffle_buffer : n:int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

since
0.7

Sampling

val sample : n:int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

since
0.7

Infix functions

module Infix = IterLabels.Infix
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind (infix version of flat_map

since
0.5
val (>|=) : 'a t -> ('a -> 'b) -> 'b t

Infix version of map

since
0.5
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

Applicative operator (product+application)

since
0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

since
0.5

Pretty printing

val pp_seq : ?⁠sep:string -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

Pretty print an iterator of 'a, using the given pretty printer to print each elements. An optional separator string can be provided.

val pp_buf : ?⁠sep:string -> (Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unit

Print into a buffer

val to_string : ?⁠sep:string -> ('a -> string) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
since
0.5.1
module IO = IterLabels.IO
\ No newline at end of file diff --git a/index.md b/index.md index a10b3e1..8bca78e 100644 --- a/index.md +++ b/index.md @@ -2,4 +2,7 @@ # Iter - [1.2](1.2) +- [1.1](1.1) +- [1.0](1.0) + - [dev](dev)