Erlang lazy list library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fixed zlist_st to map Dec 13, 2016
test Implemented zlist with state: zlist_st Sep 30, 2016
.gitignore Init Feb 28, 2016
.travis.yml Get rid of r17 in .travis.yml Dec 27, 2016
LICENSE Init Feb 28, 2016
README.md Updated README.md Dec 27, 2016
rebar.config Better coveralls script Apr 20, 2016
rebar.config.script Better coveralls script Apr 20, 2016
rebar.lock Fixed README.md Sep 27, 2016

README.md

Build Status Coveralls GitHub tag Hex.pm

Erlang zlist: a lazy sequences library.


Description

Unlike https://github.com/vjache/erlang-zlists zlist() is a function that returns improper list with data and next zlist or an empty list. You can use it to organize lazy evolution or backpressure.

Simple infinite iterator:

1> SimpleZ = fun Loop() -> [1|Loop] end.
#Fun<erl_eval.44.90072148>

2> zlist:take(10, SimpleZ).
{[1,1,1,1,1,1,1,1,1,1],#Fun<erl_eval.62.90072148>}

Usage

Integrate to your project

This is a rebar'ized project, so, if you are already using rebar, just insert a reference to this git repo at your rebar.config.

Examples

1> Z = zlist:recurrent(fun(A) -> A + 1 end, 0).
#Fun<zlist.14.21462417>

2> zlist:take(10, Z).
{[1,2,3,4,5,6,7,8,9,10],#Fun<zlist.14.21462417>}

3> Z2 = zlist:map(fun(A) -> A * 2 end, Z).
#Fun<zlist.3.21462417>

4> zlist:take(10, Z2).
{[2,4,6,8,10,12,14,16,18,20],#Fun<zlist.3.21462417>}

5> ZL = zlist:from_list([1,2,5]).
#Fun<zlist.12.21462417>

6> zlist:to_list(ZL).
[1,2,5]

7> ZR = zlist:ciclyc(ZL).
#Fun<zlist.17.21462417>

8> zlist:take(10, ZR).
{[1,2,5,1,2,5,1,2,5,1],#Fun<zlist.17.21462417>}

9> Z3 = zlist:flatmap(fun(A) -> zlist:from_list([-A, A]) end, Z2).
#Fun<zlist.6.21462417>

10> zlist:take(10, Z3).
{[-2,2,-4,4,-6,6,-8,8,-10,10],#Fun<zlist.10.21462417>}

Warnings !!!

With zlist you are working with potentially infinite data. Don't use to_list/1, foreach/2, fold/3 functions until you know that zlist is finite state. Use dropwhen/1 before, or take/2 instead.