Misc changes.

This commit is contained in:
Drup 2019-03-08 18:03:45 +01:00
parent fd8ae7559e
commit 04b8f554d4
3 changed files with 43 additions and 49 deletions

View file

@ -1,8 +0,0 @@
S src
S bench/
S tests/
B _build/src
B _build/tests/
B _build/bench/
PKG oUnit qcheck result benchmark
FLG -safe-string -w+a-4-44-48-60@8

View file

@ -1,9 +0,0 @@
#directory "_build/src";;
#load "iter.cma";;
open Iter.Infix;;
#directory "_build/src/bigarray/";;
#load "bigarray.cma";;
(* vim:syntax=ocaml *)

View file

@ -1,50 +1,39 @@
# Iter # Iter [![build status](https://travis-ci.org/c-cube/iter.svg?branch=master)](https://travis-ci.org/c-cube/iter) [![docs](https://img.shields.io/badge/doc-online-blue.svg)][doc]
Simple abstraction over `iter` functions, intended to iterate efficiently Simple abstraction over `iter` functions, intended to iterate efficiently
on collections while performing some transformations. Used to be called `Sequence`. on collections while performing some transformations.
```ocaml
# #require "iter";;
# let p x = x mod 5 = 0 in
Iter.(1 -- 5_000 |> filter p |> map (fun x -> x * x) |> fold (+) 0);;
- : int = 8345837500
```
Common operations supported by `Iter` include Common operations supported by `Iter` include
`filter`, `map`, `take`, `drop`, `append`, `flat_map`, etc. `filter`, `map`, `take`, `drop`, `append`, `flat_map`, etc.
`Iter` is not designed to be as general-purpose or flexible as, say, `Iter` is not designed to be as general-purpose or flexible as `Seq`.
Batteries' `'a Enum.t`. Rather, it aims at providing a very simple and efficient 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) 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, one intermediate closure to do so. For instance, iterating on keys, or values,
of a `Hashtbl.t`, without creating a list. of a `Hashtbl.t`, without creating a list.
Similarly, the code above is turned into a single optimized
[![build status](https://travis-ci.org/c-cube/iter.svg?branch=master)](https://travis-ci.org/c-cube/iter) for loop with `flambda`.
## Documentation ## Documentation
There is only one important type, `'a Iter.t`, and lots of functions built There is only one important type, `'a Iter.t`, and lots of functions built
around this type. around this type.
To get an overview of iter (originally "sequence"), its origins and why it was created, See [the online API][doc]
you can start with [the slides of a talk](http://simon.cedeela.fr/assets/talks/sequence.pdf)
I (@c-cube) made at some OCaml meeting.
See [the online API](https://c-cube.github.io/iter/)
for more details on the set of available functions. for more details on the set of available functions.
Some examples can be found below.
## Build [doc]: https://c-cube.github.io/iter/
1. via opam `opam install iter` The library used to be called `Sequence`.
2. manually (need OCaml >= 4.02.0): `make all install` Some historical perspective is provided
in [this talk](http://simon.cedeela.fr/assets/talks/sequence.pdf)
If you have [qtest](https://github.com/vincent-hugot/qtest) installed, given by @c-cube at some OCaml meeting.
you can build and run tests with
```
$ make test
```
If you have [benchmarks](https://github.com/Chris00/ocaml-benchmark) installed,
you can build and run benchmarks with
```
$ make benchs
```
To see how to use the library, check the following tutorial.
The `tests` and `examples` directories also have some examples, but they're a bit arcane.
## Short Tutorial ## Short Tutorial
@ -57,7 +46,6 @@ With iter, if the source structure provides a
`iter` function (or a `to_iter` wrapper), it becomes: `iter` function (or a `to_iter` wrapper), it becomes:
```ocaml ```ocaml
# #require "iter";;
# let q : int Queue.t = Queue.create();; # let q : int Queue.t = Queue.create();;
val q : int Queue.t = <abstr> val q : int Queue.t = <abstr>
# Iter.( 1 -- 10 |> to_queue q);; # Iter.( 1 -- 10 |> to_queue q);;
@ -230,6 +218,29 @@ becomes a if test).
For more details, you can read http://gallium.inria.fr/blog/generators-iterators-control-and-continuations/ . For more details, you can read http://gallium.inria.fr/blog/generators-iterators-control-and-continuations/ .
## Build
1. via opam `opam install iter`
2. manually (need OCaml >= 4.02.0): `make all install`
If you have [qtest](https://github.com/vincent-hugot/qtest) installed,
you can build and run tests with
```
$ make test
```
If you have [benchmarks](https://github.com/Chris00/ocaml-benchmark) installed,
you can build and run benchmarks with
```
$ make benchs
```
To see how to use the library, check the following tutorial.
The `tests` and `examples` directories also have some examples, but they're a bit arcane.
## License ## License
Iter is available under the BSD license. Iter is available under the BSD license.