From 97d4ac78a5a807a8e08037ada95b559884c8b7dc Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 13 Dec 2018 18:31:41 -0600 Subject: [PATCH] chore: rename to `iter` --- README.adoc | 80 +++++++++---------- qtest/Makefile | 4 +- qtest/dune | 2 +- sequence.opam | 20 ++--- src/{Sequence.ml => Iter.ml} | 38 ++++----- src/{Sequence.mli => Iter.mli} | 40 +++++----- src/IterLabels.ml | 1 + src/{SequenceLabels.mli => IterLabels.mli} | 40 +++++----- src/SequenceLabels.ml | 1 - .../{SequenceBigarray.ml => IterBigarray.ml} | 0 ...{SequenceBigarray.mli => IterBigarray.mli} | 4 +- src/bigarray/dune | 6 +- src/dune | 6 +- src/sequence/Sequence.ml | 6 ++ src/sequence/SequenceLabels.ml | 4 + src/sequence/dune | 6 ++ 16 files changed, 133 insertions(+), 125 deletions(-) rename src/{Sequence.ml => Iter.ml} (97%) rename src/{Sequence.mli => Iter.mli} (96%) create mode 100644 src/IterLabels.ml rename src/{SequenceLabels.mli => IterLabels.mli} (96%) delete mode 100644 src/SequenceLabels.ml rename src/bigarray/{SequenceBigarray.ml => IterBigarray.ml} (100%) rename src/bigarray/{SequenceBigarray.mli => IterBigarray.mli} (71%) create mode 100644 src/sequence/Sequence.ml create mode 100644 src/sequence/SequenceLabels.ml create mode 100644 src/sequence/dune diff --git a/README.adoc b/README.adoc index 9475537..cf0066a 100644 --- a/README.adoc +++ b/README.adoc @@ -1,36 +1,36 @@ -= Sequence += Iter :toc: macro :source-highlighter: pygments -Simple sequence abstract datatype, intended to iterate efficiently -on collections while performing some transformations. +Simple abstraction over `iter` functions, intended to iterate efficiently +on collections while performing some transformations. Used to be called `Sequence`. -Common operations supported by Sequence include +Common operations supported by `Iter` include `filter`, `map`, `take`, `drop`, `append`, `flat_map`, etc. -Sequence is not designed to be as general-purpose or flexible as, say, +`Iter` is not designed to be as general-purpose or flexible as, say, Batteries' `'a Enum.t`. Rather, it aims at providing a very simple and efficient way of iterating on a finite number of values, only allocating (most of the time) one intermediate closure to do so. For instance, iterating on keys, or values, of a `Hashtbl.t`, without creating a list. -image::https://travis-ci.org/c-cube/sequence.svg?branch=master[alt="Build Status", link="https://travis-ci.org/c-cube/sequence"] +image::https://travis-ci.org/c-cube/iter.svg?branch=master[alt="Build Status", link="https://travis-ci.org/c-cube/iter"] toc::[] == Documentation -There is only one important type, `'a Sequence.t`, and lots of functions built +There is only one important type, `'a Iter.t`, and lots of functions built around this type. -To get an overview of sequence, its origins and why it was created, -you can start with http://cedeela.fr/~simon/talks/sequence.pdf[the slides of a talk] +To get an overview of iter (originally "sequence"), its origins and why it was created, +you can start with http://simon.cedeela.fr/assets/talks/sequence.pdf[the slides of a talk] I (@c-cube) made at some OCaml meeting. -See https://c-cube.github.io/sequence/[the online API] +See https://c-cube.github.io/iter/[the online API] for more details on the set of available functions. == Build -1. via opam `opam install sequence` +1. via opam `opam install iter` 2. manually (need OCaml >= 4.02.0): `make all install` If you have https://github.com/vincent-hugot/iTeML[qtest] installed, @@ -51,7 +51,7 @@ $ ./benchs.native To see how to use the library, check the `examples` directory. `tests.ml` has a few examples of how to convert basic data structures into -sequences, and conversely. +iterators, and conversely. == Short Tutorial @@ -60,21 +60,21 @@ sequences, and conversely. Conversion between n container types would take n² functions. In practice, for a given collection we can at best hope for `to_list` and `of_list`. -With sequence, if the source structure provides a -`iter` function (or a `to_seq` wrapper), it becomes: +With iter, if the source structure provides a +`iter` function (or a `to_iter` wrapper), it becomes: [source,OCaml] ---- # let q = Queue.create();; -# Sequence.( 1 -- 10 |> to_queue q);; +# Iter.( 1 -- 10 |> to_queue q);; - : unit = () -# Sequence.of_queue q |> Sequence.to_list ;; +# Iter.of_queue q |> Iter.to_list ;; - : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10] # let s = Stack.create();; -# Sequence.(of_queue q |> to_stack s);; +# Iter.(of_queue q |> to_stack s);; - : unit = () -# Sequence.of_stack s |> Sequence.to_list ;; +# Iter.of_stack s |> Iter.to_list ;; - : int list = [10; 9; 8; 7; 6; 5; 4; 3; 2; 1] ---- @@ -97,7 +97,7 @@ underlying hash function): - : int = 11 (* now to get the values *) -# Sequence.of_hashtbl h |> Sequence.map snd |> Sequence.to_list;; +# Iter.of_hashtbl h |> Iter.map snd |> Iter.to_list;; - : string list = ["6"; "2"; "8"; "7"; "3"; "5"; "4"; "9"; "0"; "10"; "1"] ---- @@ -105,15 +105,15 @@ underlying hash function): The `for` loop is a bit limited, and lacks compositionality. Instead, it can be more convenient and readable to -use `Sequence.(--) : int -> int -> int Sequence.t`. +use `Iter.(--) : int -> int -> int Iter.t`. [source,OCaml] ---- -# Sequence.(1 -- 10_000_000 |> fold (+) 0);; +# Iter.(1 -- 10_000_000 |> fold (+) 0);; - : int = 50000005000000 # let p x = x mod 5 = 0 in - Sequence.(1 -- 5_000 + Iter.(1 -- 5_000 |> filter p |> map (fun x -> x * x) |> fold (+) 0 @@ -136,28 +136,28 @@ A small λ-calculus AST, and some operations on it. | App of term * term | Lambda of term ;; -# let rec subterms : term -> term Sequence.t = +# let rec subterms : term -> term Iter.t = fun t -> - let open Sequence.Infix in - Sequence.cons t + let open Iter.Infix in + Iter.cons t (match t with - | Var _ -> Sequence.empty + | Var _ -> Iter.empty | Lambda u -> subterms u | App (a,b) -> - Sequence.append (subterms a) (subterms b)) + Iter.append (subterms a) (subterms b)) ;; (* Now we can define many other functions easily! *) # let vars t = - Sequence.filter_map + Iter.filter_map (function Var s -> Some s | _ -> None) (subterms t) ;; val vars : term -> string sequence = -# let size t = Sequence.length (subterms t) ;; +# let size t = Iter.length (subterms t) ;; val size : term -> int = -# let vars_list l = Sequence.(of_list l |> flat_map vars);; +# let vars_list l = Iter.(of_list l |> flat_map vars);; val vars_list : term list -> string sequence = ---- @@ -165,14 +165,14 @@ val vars_list : term list -> string sequence = Makes it easy to write backtracking code (a non-deterministic function returning several `'a` -will just return a `'a Sequence.t`). +will just return a `'a Iter.t`). Here, we generate all permutations of a list by enumerating the ways we can insert an element in a list. [source,OCaml] ---- -# open Sequence.Infix;; -# module S = Sequence ;; +# open Iter.Infix;; +# module S = Iter ;; # let rec insert x l = match l with | [] -> S.return [x] | y :: tl -> @@ -218,25 +218,25 @@ let zip (g1: 'a Gen.t) (g2:'b Gen.t) : ('a * 'b) Gen.t = Some (x,y) ---- -- `Sequence` is an *internal* iterator. When one wishes to iterate over - an `'a Sequence.t`, one has to give a callback `f : 'a -> unit` +- `Iter` is an *internal* iterator. When one wishes to iterate over + an `'a Iter.t`, one has to give a callback `f : 'a -> unit` that is called in succession over every element of the sequence. Control is not handed back to the caller before the whole iteration is over. - This makes `zip` impossible to implement. However, the type `'a Sequence.t` + This makes `zip` impossible to implement. However, the type `'a Iter.t` is general enough that it can be extracted from any classic `iter` function, including from data structures such as `Map.S.t` or `Set.S.t` or `Hashtbl.t`; one cannot obtain a `'a Gen.t` from these without having access to the internal data structure. -In short, `'a Gen.t` is more expressive than `'a Sequence.t`, but it also +In short, `'a Gen.t` is more expressive than `'a Iter.t`, but it also requires more knowledge of the underlying source of items. -For some operations such as `map` or `flat_map`, Sequence is also extremely +For some operations such as `map` or `flat_map`, Iter is also extremely efficient and will, if flambda permits, be totally removed at -compile time (e.g. `Sequence.(--)` becomes a for loop, and `Sequence.filter` +compile time (e.g. `Iter.(--)` becomes a for loop, and `Iter.filter` becomes a if test). For more details, you can read http://gallium.inria.fr/blog/generators-iterators-control-and-continuations/ . == License -Sequence is available under the BSD license. +Iter is available under the BSD license. diff --git a/qtest/Makefile b/qtest/Makefile index 177e0a8..39705a4 100644 --- a/qtest/Makefile +++ b/qtest/Makefile @@ -1,13 +1,13 @@ QTEST_PREAMBLE='' -DONTTEST=../src/sequenceLabels.ml ../src/mkflags.ml +DONTTEST=../src/iterLabels.ml ../src/mkflags.ml QTESTABLE=$(filter-out $(DONTTEST), \ $(wildcard ../src/*.ml) \ $(wildcard ../src/*.mli) \ ) qtest-gen: - @rm run_qtest.ml || true + @rm run_qtest.ml 2>/dev/null || true @if which qtest > /dev/null ; then \ qtest extract --preamble $(QTEST_PREAMBLE) \ -o run_qtest.ml \ diff --git a/qtest/dune b/qtest/dune index 2e4267d..0a46b4f 100644 --- a/qtest/dune +++ b/qtest/dune @@ -11,7 +11,7 @@ (executable (name run_qtest) (flags :standard -warn-error -a+8 -safe-string -w -33) - (libraries sequence qcheck) + (libraries iter qcheck) ) (alias diff --git a/sequence.opam b/sequence.opam index 62ec217..f2f83f8 100644 --- a/sequence.opam +++ b/sequence.opam @@ -4,26 +4,18 @@ version: "1.1" author: "Simon Cruanes" maintainer: "simon.cruanes.2007@m4x.org" license: "BSD-2-clauses" -synopsis: "Simple sequence abstract datatype, intended to iterate efficiently -on collections while performing some transformations" +synopsis: "compatibility package for `iter`" build: [ ["dune" "build" "@install" "-p" name "-j" jobs] - ["dune" "build" "@doc" "-p" name] {with-doc} - ["dune" "runtest" "-p" name] {with-test} ] depends: [ - "base-bytes" - "result" - "dune" {build} - "qcheck" {with-test} - "qtest" {with-test} - "odoc" {with-doc} + "iter" ] tags: [ "sequence" "iterator" "iter" "fold" ] -homepage: "https://github.com/c-cube/sequence/" +homepage: "https://github.com/c-cube/iter/" depopts: [ "base-bigarray" ] -doc: "https://c-cube.github.io/sequence/" -bug-reports: "https://github.com/c-cube/sequence/issues" -dev-repo: "git+https://github.com/c-cube/sequence.git" +doc: "https://c-cube.github.io/iter/" +bug-reports: "https://github.com/c-cube/iter/issues" +dev-repo: "git+https://github.com/c-cube/iter.git" diff --git a/src/Sequence.ml b/src/Iter.ml similarity index 97% rename from src/Sequence.ml rename to src/Iter.ml index c2403ac..406b2ab 100644 --- a/src/Sequence.ml +++ b/src/Iter.ml @@ -1,12 +1,12 @@ -(* This file is free software, part of sequence. See file "license" for more details. *) +(* This file is free software, part of iter. See file "license" for more details. *) (** {1 Simple and Efficient Iterators} *) -(** Sequence abstract iterator type *) +(** Iter abstract iterator type *) type 'a t = ('a -> unit) -> unit -type 'a sequence = 'a t +type 'a iter = 'a t (*$inject let pp_ilist = Q.Print.(list int) @@ -15,7 +15,7 @@ type 'a sequence = 'a t type 'a equal = 'a -> 'a -> bool type 'a hash = 'a -> int -(** Build a sequence from a iter function *) +(** Build an iterator from a iter function *) let from_iter f = f let rec from_fun f k = match f () with @@ -803,7 +803,7 @@ let head seq = let head_exn seq = match head seq with - | None -> invalid_arg "Sequence.head_exn" + | None -> invalid_arg "Iter.head_exn" | Some x -> x exception ExitTake @@ -967,7 +967,7 @@ let is_empty seq = try seq (fun _ -> raise_notrace ExitIsEmpty); true with ExitIsEmpty -> false -(** {2 Transform a sequence} *) +(** {2 Transform an iterator} *) let zip_i seq k = let r = ref 0 in @@ -1181,13 +1181,13 @@ let to_klist seq = let l = MList.of_seq seq in MList.to_klist l -(** {2 Functorial conversions between sets and sequences} *) +(** {2 Functorial conversions between sets and iterators} *) module Set = struct module type S = sig include Set.S - val of_seq : elt sequence -> t - val to_seq : t -> elt sequence + val of_seq : elt iter -> t + val to_seq : t -> elt iter val to_list : t -> elt list val of_list : elt list -> t end @@ -1212,20 +1212,20 @@ module Set = struct end end -(** {2 Conversion between maps and sequences.} *) +(** {2 Conversion between maps and iterators.} *) module Map = struct module type S = sig include Map.S - 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_seq : 'a t -> (key * 'a) iter + val of_seq : (key * 'a) iter -> 'a t + val keys : 'a t -> key iter + val values : 'a t -> 'a iter val to_list : 'a t -> (key * 'a) list val of_list : (key * 'a) list -> 'a t end - (** Adapt a pre-existing Map module to make it sequence-aware *) + (** Adapt a pre-existing Map module to make it iterator-aware *) module Adapt(M : Map.S) = struct let to_seq_ m = from_iter (fun k -> M.iter (fun x y -> k (x,y)) m) @@ -1244,14 +1244,14 @@ module Map = struct let of_seq = of_seq_ end - (** Create an enriched Map module, with sequence-aware functions *) + (** Create an enriched Map module, with iterator-aware functions *) module Make(V : Map.OrderedType) : S with type key = V.t = struct module M = Map.Make(V) include Adapt(M) end end -(** {2 Infinite sequences of random values} *) +(** {2 Infinite iterators of random values} *) let random_int bound = forever (fun () -> Random.int bound) @@ -1359,9 +1359,9 @@ end include Infix -(** {2 Pretty printing of sequences} *) +(** {2 Pretty printing of iterators} *) -(** Pretty print a sequence of ['a], using the given pretty printer +(** Pretty print an ['a iter], using the given pretty printer to print each elements. An optional separator string can be provided. *) let pp_seq ?(sep=", ") pp_elt formatter seq = let first = ref true in diff --git a/src/Sequence.mli b/src/Iter.mli similarity index 96% rename from src/Sequence.mli rename to src/Iter.mli index bbddc5a..6585e09 100644 --- a/src/Sequence.mli +++ b/src/Iter.mli @@ -1,5 +1,5 @@ -(* This file is free software, part of sequence. See file "license" for more details. *) +(* This file is free software, part of iter. See file "license" for more details. *) (** {1 Simple and Efficient Iterators} *) @@ -34,7 +34,7 @@ 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 +type +'a iter = 'a t (** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit] has been removed and subsumed by [('a * 'b) t] @since 1.0 *) @@ -58,7 +58,7 @@ val singleton : 'a -> 'a t (** Singleton sequence, with exactly one element. *) val doubleton : 'a -> 'a -> 'a t -(** Sequence with exactly two elements *) +(** Iterator with exactly two elements *) val init : (int -> 'a) -> 'a t (** [init f] is the infinite sequence [f 0; f 1; f 2; …]. @@ -85,7 +85,7 @@ 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. +(** Iterator 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}. *) @@ -420,7 +420,7 @@ val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t and unfoldr recurses with [b']. *) val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t -(** Sequence of intermediate results *) +(** Iterator of intermediate results *) val max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a option (** Max element of the sequence, using the given comparison function. @@ -531,7 +531,7 @@ 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 +(** [array_slice a i j] Iterator of elements whose indexes range from [i] to [j] *) val of_opt : 'a option -> 'a t @@ -539,7 +539,7 @@ val of_opt : 'a option -> 'a t @since 0.5.1 *) val of_stream : 'a Stream.t -> 'a t -(** Sequence of elements of a stream (usable only once) *) +(** 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) *) @@ -548,13 +548,13 @@ 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]) *) +(** Iterator 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 *) +(** Iterator 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 @@ -568,7 +568,7 @@ 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 *) +(** 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 @@ -638,8 +638,8 @@ val to_klist : 'a t -> 'a klist module Set : sig module type S = sig include Set.S - val of_seq : elt sequence -> t - val to_seq : t -> elt sequence + val of_seq : elt iter -> t + val to_seq : t -> elt iter val to_list : t -> elt list val of_list : elt list -> t end @@ -656,10 +656,10 @@ end module Map : sig module type S = sig include Map.S - 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_seq : 'a t -> (key * 'a) iter + val of_seq : (key * 'a) iter -> 'a t + val keys : 'a t -> key iter + val values : 'a t -> 'a iter val to_list : 'a t -> (key * 'a) list val of_list : (key * 'a) list -> 'a t end @@ -683,7 +683,7 @@ val random_bool : bool t val random_float : float -> float t val random_array : 'a array -> 'a t -(** Sequence of choices of an element in the array *) +(** Iterator 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 @@ -765,19 +765,19 @@ val to_string : ?sep:string -> ('a -> string) -> 'a t -> string Example: copy a file ["a"] into file ["b"], removing blank lines: {[ - Sequence.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");; + Iterator.(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");; + Iterator.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 + Iterator.IO.lines "a" |> Iterator.to_list ]} @since 0.5.1 *) diff --git a/src/IterLabels.ml b/src/IterLabels.ml new file mode 100644 index 0000000..c27720b --- /dev/null +++ b/src/IterLabels.ml @@ -0,0 +1 @@ +include Iter diff --git a/src/SequenceLabels.mli b/src/IterLabels.mli similarity index 96% rename from src/SequenceLabels.mli rename to src/IterLabels.mli index 0cd7dd3..1abce16 100644 --- a/src/SequenceLabels.mli +++ b/src/IterLabels.mli @@ -4,7 +4,7 @@ (** {1 Simple and Efficient Iterators} - Version of {!Sequence} with labels + Version of {!Iterator} with labels @since 0.5.5 *) @@ -12,7 +12,7 @@ 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 +type +'a iter = 'a t (** {b NOTE} Type [('a, 'b) t2 = ('a -> 'b -> unit) -> unit] has been removed and subsumed by [('a * 'b) t] @since 1.0 *) @@ -36,7 +36,7 @@ val singleton : 'a -> 'a t (** Singleton sequence, with exactly one element. *) val doubleton : 'a -> 'a -> 'a t -(** Sequence with exactly two elements *) +(** Iterator with exactly two elements *) val init : f:(int -> 'a) -> 'a t (** [init f] is the infinite sequence [f 0; f 1; f 2; …]. @@ -63,7 +63,7 @@ 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. +(** Iterator 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}. *) @@ -392,7 +392,7 @@ val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t and unfoldr recurses with [b']. *) val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t -(** Sequence of intermediate results *) +(** Iterator of intermediate results *) val max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a option (** Max element of the sequence, using the given comparison function. @@ -503,7 +503,7 @@ 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 +(** [array_slice a i j] Iterator of elements whose indexes range from [i] to [j] *) val of_opt : 'a option -> 'a t @@ -511,7 +511,7 @@ val of_opt : 'a option -> 'a t @since 0.5.1 *) val of_stream : 'a Stream.t -> 'a t -(** Sequence of elements of a stream (usable only once) *) +(** 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) *) @@ -520,13 +520,13 @@ 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]) *) +(** Iterator 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 *) +(** Iterator 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 @@ -540,7 +540,7 @@ 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 *) +(** 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 @@ -611,8 +611,8 @@ val to_klist : 'a t -> 'a klist module Set : sig module type S = sig include Set.S - val of_seq : elt sequence -> t - val to_seq : t -> elt sequence + val of_seq : elt iter -> t + val to_seq : t -> elt iter val to_list : t -> elt list val of_list : elt list -> t end @@ -629,10 +629,10 @@ end module Map : sig module type S = sig include Map.S - 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_seq : 'a t -> (key * 'a) iter + val of_seq : (key * 'a) iter -> 'a t + val keys : 'a t -> key iter + val values : 'a t -> 'a iter val to_list : 'a t -> (key * 'a) list val of_list : (key * 'a) list -> 'a t end @@ -656,7 +656,7 @@ val random_bool : bool t val random_float : float -> float t val random_array : 'a array -> 'a t -(** Sequence of choices of an element in the array *) +(** Iterator 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 @@ -739,19 +739,19 @@ val to_string : ?sep:string -> ('a -> string) -> 'a t -> string Example: copy a file ["a"] into file ["b"], removing blank lines: {[ - Sequence.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");; + Iterator.(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");; + Iterator.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 + Iterator.IO.lines "a" |> Iterator.to_list ]} @since 0.5.1 *) diff --git a/src/SequenceLabels.ml b/src/SequenceLabels.ml deleted file mode 100644 index fb15e92..0000000 --- a/src/SequenceLabels.ml +++ /dev/null @@ -1 +0,0 @@ -include Sequence diff --git a/src/bigarray/SequenceBigarray.ml b/src/bigarray/IterBigarray.ml similarity index 100% rename from src/bigarray/SequenceBigarray.ml rename to src/bigarray/IterBigarray.ml diff --git a/src/bigarray/SequenceBigarray.mli b/src/bigarray/IterBigarray.mli similarity index 71% rename from src/bigarray/SequenceBigarray.mli rename to src/bigarray/IterBigarray.mli index 8af4105..de96424 100644 --- a/src/bigarray/SequenceBigarray.mli +++ b/src/bigarray/IterBigarray.mli @@ -5,8 +5,8 @@ @since 0.5.4 *) -val of_bigarray : ('a, _, _) Bigarray.Array1.t -> 'a Sequence.t +val of_bigarray : ('a, _, _) Bigarray.Array1.t -> 'a Iter.t (** Iterate on the elements of a 1-D array *) -val mmap : string -> char Sequence.t +val mmap : string -> char Iter.t (** Map the file into memory, and read the characters. *) diff --git a/src/bigarray/dune b/src/bigarray/dune index 2c7bf70..0c5d849 100644 --- a/src/bigarray/dune +++ b/src/bigarray/dune @@ -1,8 +1,8 @@ (library - (name sequence_bigarray) - (public_name sequence.bigarray) - (libraries sequence bigarray) + (name iter_bigarray) + (public_name iter.bigarray) + (libraries iter bigarray) (wrapped false) (optional) (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string) diff --git a/src/dune b/src/dune index 25c3ab1..7fc8a02 100644 --- a/src/dune +++ b/src/dune @@ -7,10 +7,10 @@ ) (library - (name sequence) - (public_name sequence) + (name iter) + (public_name iter) (wrapped false) - (modules Sequence SequenceLabels) + (modules Iter IterLabels) (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels) (ocamlopt_flags :standard (:include flambda.flags)) (libraries bytes result) diff --git a/src/sequence/Sequence.ml b/src/sequence/Sequence.ml new file mode 100644 index 0000000..abf3e40 --- /dev/null +++ b/src/sequence/Sequence.ml @@ -0,0 +1,6 @@ + +[@@@ocaml.deprecated "the package is now `Iter`"] + +include Iter + +type 'a sequence = 'a iter diff --git a/src/sequence/SequenceLabels.ml b/src/sequence/SequenceLabels.ml new file mode 100644 index 0000000..0c0feda --- /dev/null +++ b/src/sequence/SequenceLabels.ml @@ -0,0 +1,4 @@ + +[@@@ocaml.deprecated "the package is now `Iter`"] + +include IterLabels diff --git a/src/sequence/dune b/src/sequence/dune new file mode 100644 index 0000000..288f8c9 --- /dev/null +++ b/src/sequence/dune @@ -0,0 +1,6 @@ + +(library + (name sequence) + (public_name sequence) + (wrapped false) + (libraries iter))