
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Lazy evaluation utilities for JavaScript powered by ES6 iterators and generators
Lazy evaluation utilities for JavaScript powered by ES6 iterators and generators.
Well-tested and with Flow type definitions included.
Compatible with Node v6.11.2 LTS or later.
npm install --save laziness
const { default: Laziness, range } = require('laziness');
// logs numbers 0, 1, ..., 9 one per line
for (const x of range(0, 10)) {
console.log(x);
}
// the same
Laziness.from(range(0, 10))
.forEach(x => console.log(x));
function* fib() {
yield 1;
yield 1;
const [fib1, fib2] = Laziness.from(fib()).tee();
yield* fib1.map2((x, y) => x + y, fib2.tail());
}
fib() // 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Infinite Iterators
Generates all elements of the iterable. Once the original iterable is exhausted, yields all elements again. Repeats indefinitely.
Parameters
iter Iterable<T>Examples
cycle('ABC') // 'A', 'B', 'C', 'A', 'B', 'C', ...
Returns Generator<T, void, void>
Parameters
Examples
range(0, Infinity) // 0, 1, 2, ...
Returns Generator<number, void, void>
Repeats value endlessly or up to limit times.
Parameters
value Tlimit number (optional, default Infinity)Examples
repeat(5) // 5, 5, 5, 5, ...
repeat(10, 3) // 10, 10, 10
Returns Generator<T, void, void>
Basic functions
Analogical to Array.prototype.filter
Parameters
iter Iterable<T>callback function (T): booleanReturns Generator<T, void, void>
Analogical to Array.prototype.forEach
Parameters
iter Iterable<T>callback function (T): voidReturns void
Analogical to Array.prototype.map
Parameters
iter Iterable<T>callback function (T): UReturns Generator<U, void, void>
Generates values of the function when applied arguments from each of the iterables. Stops when the shortest iterable is exhausted.
Parameters
callback function (U, V): Titer1 Iterable<U>iter2 Iterable<V>Examples
map2((x, y) => x + y, range(1, 4), range(10, 40, 10)) // 11, 22, 33
Returns Generator<T, void, void>
Analogical to Array.prototype.slice
Parameters
Returns Generator<T, void, void>
Skips first element of iterable
Parameters
iter Iterable<T>Returns Generator<T, void, void>
Clone interable into n independent instances
Parameters
iter Iterable<T>n number (optional, default 2)Returns Array<Generator<T, void, void>>
Handy wrapper for common operations on iterables.
Convenient wrapper for chaining calls to library functions.
You can also use it as iterable.
Parameters
iter Iterable<T>Examples
Array.from(new Laziness([1, 2, 3])) // 1, 2, 3
function* fib() {
yield 1;
yield 1;
const [fib1, fib2] = Laziness.from(fib()).tee();
yield* fib1.map2((x, y) => x + y, fib2.tail());
}
fib() // 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
See filter
Parameters
callback function (T): booleanReturns Laziness<T>
See forEach
Parameters
callback function (T): voidSee map
Parameters
callback function (T): UReturns Laziness<U>
See map2
Parameters
callback function (T): Uiter2 Iterable<V>Returns Laziness<U>
See slice
Parameters
Returns Laziness<T>
See tail
Returns Laziness<T>
See tee
Parameters
n number (optional, default 2)Returns Array<T>
Same as new Laziness(iter)
Parameters
iter Iterable<T>Returns Laziness<T>
FAQs
Lazy evaluation utilities for JavaScript powered by ES6 iterators and generators
We found that laziness demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.