lazyseq

lazy sequence mapreduce generator

lazy sequence (multi-dimensional capable) mapreduce / generator

For node.js or browser

var datasets = { 'c': ['a', 'b', 'c'], 'a': [1,2,3,4], 'b': [1,2,3,4] };
 
var LazySeq = require('lazyseq');
 
var seq = new LazySeq(datasets).cartesian();
 
seq.next(); // { 'a': 1, 'b': 1, 'c': 'a' } 
seq.next(); // { 'a': 1, 'b': 1, 'c': 'b' } 
seq.next(); // { 'a': 1, 'b': 1, 'c': 'c' } 
seq.next(); // { 'a': 2, 'b': 1, 'c': 'a' } 
seq.next(); // { 'a': 2, 'b': 1, 'c': 'b' } 
 
seq.take(5); // returns array of next 5 in the sequence 

Notice the ordering of the sequence is related to the order of the dataset being passed in.

Priority is in the order defined ( c, then a, then b ).

(Example shown above)

var seq = new LazySeq(datasets)
              .map(function(item) {
                return item.+ item.+ item.c;
              });
 
seq.next(); // '11a' 
seq.next(); // '22b' 
seq.next(); // '33c' 
var seq = new LazySeq(datasets)
              .reduce(function(prevcurr) {
                // first run 
                if (prev.a) {
                  return prev.+ curr.a;
                } else {
                  return prev + curr.b;
                }
              });
 
seq.next(); // 3  // first run: 1 + 2 
seq.next(); // 4  // 3 + 1 
seq.next(); // 6  // 4 + 2 

All generators share the same API, which is:

Returns the next data in the sequence

Returns the next n data in the sequence

Resets the generator back to the beginning