Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (48 sloc) 2.66 KB
Welcome to a lazy sequences library. There are many possibilities
to represent and handle lazy sequences. To distinct the approach
implemented in this library from other possible ones, it is decided
to refer it as a Z-Lists, or simply zlists.
1. Design
The core module is a 'zlists'. It is analogous to module 'lists' in a STDLIB
of Erlang. It contains a base operations supported over Z-Lists.
The other modules 'zlists_X' are utility modules that bridges Z-Lists with
standard Erlang modules which may be considered as data sources e.g. 'ets',
'dets', 'mnesia', 'disk_log', 'file' etc.
2. Usage
2.1. Integrate to your project
This is a rebar'ized project so if you already using rebar
just insert a reference to this git repo at your rebar.config.
Otherwise download this repo, and run shell command "erl -make".
2.2. Examples
1> Naturals=zlists:recurrent(1, fun(N)-> N+1 end).
2> zlists:scroll(10,Naturals).
3> zlists:scroll(10,zlists:drop(5,Naturals)).
4> zlists:scroll(10,zlists:drop(500000,Naturals)).
5> Fibonacci=zlists:recurrent(1, 0, fun(X0,S0) -> {X0+S0, X0} end).
6> zlists:expand(10, Fibonacci).
7> zlists:expand(10, zlists:drop(10,Fibonacci)).
8> zlists:scroll(10, zlists:drop(10,Fibonacci)).
3. Create your own Z-List
Create your own custom zlist is easy enough, you can directly construct
a special improper list like:
[1|fun()-> L=deferred_work(),true=is_list(L),L end]
Note the | symbol between head element and tail function. If you have
already a proper list and tail function you can construct a lazy list
from them as:
zlists:new([1,2,3], fun()-> [4,5] end)
If the lazy list you want to create have an explicit recurrent nature
you can use a zlists:recurrent/2/3 to easily create a lazy list.