Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 55 lines (48 sloc) 2.721 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
==================================================================================
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).
        [1|#Fun<zlists.2.24701927>]
        2> zlists:scroll(10,Naturals).
        {[1,2,3,4,5,6,7,8,9,10],[11|#Fun<zlists.2.24701927>]}
        3> zlists:scroll(10,zlists:drop(5,Naturals)).
        {[6,7,8,9,10,11,12,13,14,15],[16|#Fun<zlists.2.24701927>]}
        4> zlists:scroll(10,zlists:drop(500000,Naturals)).
        {[500001,500002,500003,500004,500005,500006,500007,500008,
          500009,500010],
         [500011|#Fun<zlists.2.24701927>]}
        5> Fibonacci=zlists:recurrent(1, 0, fun(X0,S0) -> {X0+S0, X0} end).
        [1|#Fun<zlists.3.26975111>]
        6> zlists:expand(10, Fibonacci).
        [1,1,2,3,5,8,13,21,34,55|#Fun<zlists.3.26975111>]
        7> zlists:expand(10, zlists:drop(10,Fibonacci)).
        [89,144,233,377,610,987,1597,2584,4181,6765|
         #Fun<zlists.3.26975111>]
        8> zlists:scroll(10, zlists:drop(10,Fibonacci)).
        {[89,144,233,377,610,987,1597,2584,4181,6765],
         [10946|#Fun<zlists.3.26975111>]}
        
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.
        
Something went wrong with that request. Please try again.