as-needed

0.0.2 • Public • Published

as-needed

do things, as needed

range

for (const v of range(1, 5)) console.log(v);
1
2
3
4
5

take

for (const v of take(range(1, 100), 3)) console.log(v);
// output:
[ 1, 2, 3 ]
console.log(take([ 1, 2, 3, 4, 5 ], 3).next().value);
// output:
[ 1, 2, 3 ]

map

for (const v of map([ 1, 2, 3 ], v => v + 10)) console.log(v);
// output:
11
12
13

reduce

for (const v of reduce([ 1, 2, 3 ], (a, b) => a + b)) console.log(v);
// output:
1
3
6

filter

for (const v of filter([ 1, 2, 3, 4, 5 ], v => v % 2)) console.log(v);
// output:
1
3
5

Note: take, map, reduce, and filter accept any iterable or array-like object.

Package Sidebar

Install

npm i as-needed

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

3.35 kB

Total Files

4

Last publish

Collaborators

  • machellerogden