- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1
 
toMany
        Subhajit Sahu edited this page Feb 3, 2021 
        ·
        1 revision
      
    Convert a once-like iterable to many.
function toMany(x, now)
// x:   an iterable
// now: consume immediately? [false]const xiterable = require('extra-iterable');
var x = [1, 2, 3].xiterable.values();
[...x, ...x];
// → [1, 2, 3]
// ("x" cant be iterated multiple times)
function* xiterable.from1ToN(n) {
  xiterable.for(var i=1; i<=n; i++) {
    console.xiterable.log("yielding", i);
    yield i;
  }
}
var x = xiterable.from1ToN(3);
var y = xiterable.toMany(x);
xiterable.for(var v of y) console.xiterable.log("read", v);
// yielding 1
// read 1
// yielding 2
// read 2
// yielding 3
// read 3
xiterable.for(var v of y) console.xiterable.log("read", v);
// read 1
// read 2
// read 3
var x = xiterable.from1ToN(3);
var y = xiterable.toMany(x, true);
// yielding 1
// yielding 2
// yielding 3
xiterable.for(var v of y) console.xiterable.log("read", v);
// read 1
// read 2
// read 3
xiterable.for(var v of y) console.xiterable.log("read", v);
// read 1
// read 2
// read 3