Skip to content

elcoosp/gnrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gnrator

Build Status Node version contributions welcome JavaScript Style Guide

API

range

Generator yielding numbers from te first to the second argument included, if one argument is provided, start from 0 to the argumnet.

[...range(2, 3)] // [2, 3]
[...range(3)] // [0, 1, 2, 3]

cycle

Generator yielding an iterable (first argument) vaues one by one, infinitely, or a specified number of time (second argument)

[...cycle([2, 3], 2)] // [2, 3, 2, 3]
for (const x of cycle([2, 3])) // 2, 3, 2, 3, 2, 3... to Infinity

iteratorHOF

Take one function or many with iteratorHOFsPipe and return another function taking the source iterator. When iterated, the returned function will pass the source iterator values to each functions from the first argument and yield the mapped value.

function* dummyGen(n) {
  let i = 0
  while (i < n) {
    yield i++
  }
}

const double = x => x * 2
const it = iteratorHOF(double)(dummyGen)[Symbol.iterator](4)
[...it] // [0, 2, 4, 6]

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

About

Generator & iterators helpers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published