Gathering detailed insights and metrics for iterablefu
Gathering detailed insights and metrics for iterablefu
Gathering detailed insights and metrics for iterablefu
Gathering detailed insights and metrics for iterablefu
Small (1.2kb gz), set of functions like range, map, reduce, filter, zip, for iterable objects.
npm install iterablefu
Typescript
Module System
Node Version
NPM Version
JavaScript (99.46%)
HTML (0.54%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
45 Commits
1 Watchers
7 Branches
1 Contributors
Updated on Apr 03, 2025
Latest Version
0.4.5
Package Id
iterablefu@0.4.5
Unpacked Size
51.27 kB
Size
10.10 kB
File Count
14
NPM Version
10.9.0
Node Version
22.11.0
Published on
Nov 08, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
IterableFu
is a small (1.2kb minimized and gzipped) library of functions like range, map, reduce, filter, zip, for iterable objects.
IterableFu
has a chainable class to make it easy to chain iterable transforms. There is a chainable class factory
makeChainableIterable, so you easily can add methods, or reduce bundle size.
chainable([0, 1, 2]).map(x => 2*x).toArray()
.chainable(yourGenerator()).mapWith(yourTransformGenerator)
.If you want asynchronous iterables along with task pool, event queue, pub/sub, merge, chunk, throttle, and the like, checkout await-for-it.
1npm install --save iterablefu
If you want the chainable API, use this import.
1import { chainable } from 'iterablefu'
1import { chainable } from 'iterablefu' 2 3const iterable = chainable([1, 2, 3, 4, 5, 6]) // <-- throw any synchronous iterable in here 4 .filter(x => x % 2 === 0) // filters out odd numbers 5 .map(x => 2 * x) 6 7console.log(Array.from(iterable)) // prints [4, 8, 12]
The most used methods are probably: zip
, zipAll
, filter
, flatten
, map
, and reduce
.
The documentation has an example for each method:
ChainableIterable
If you want the functional API, use this import.
1import { generators, transforms, reducers } from 'iterablefu'
You may also specify the modules directly to reduce bundle sizes. See more in the Smaller Bundles section.
ChainableIterable
instancesIterableFu
provides three basic categories of functions:
Here's a quick example showing range
(a generator), map
(a transform), and reduce
(a reducer).
1import { chainable } from 'iterablefu' 2const answer = 3 chainable 4 .range(5) // generates 0, 1, 2, 3, 4 5 .map(x => 2 * x) // maps to 0, 2, 4, 6, 8 6 .reduce((a, x) => a + x, 0) // 0 + 2 + 4 + 6 + 8 = 20 7console.log(answer) // prints 20
Some generators can convert Arrays or any other iterable into chainable iterables.
1const d = chainable([1, 2, 3]) // makes a chainable version of [1, 2, 3] 2const e = chainable.concatenate([0, 1, 2], [3, 4]) // becomes [0, 1, 2, 3, 4] 3const f = chainable.zip([1, 2, 3], ['a', 'b', 'c']) // becomes [[1, 'a'], [2, 'b'], [3, 'c']]
There are several ways to convert back to Arrays.
1const a = Array.from(chainable.range(5)) // a has the value [0, 1, 2, 3, 4, 5] 2const b = [...chainable.range(3)] // b has the value [0, 1, 2] 3const c = chainable.range(2, 5).toArray() // c has the value [2, 3, 4, 5, 6]
Except for one method, repeatIterable
, IterableFu
only supports one-time iteration. This is because
iterators cannot be reused once done.
An iterable class like Array, can be iterated more than once because it produces a new iterator for each iteration.
1// IterableFu produces one-time use sequences 2const a = chainable.range(5) 3console.log([...a]) // print [0, 1, 2, 3, 4], iterator is now done 4console.log([...a]) // prints [] because the iterator was done before the call
To reuse an IterableFu
chain, wrap it in a function so that a new Generator object is returned each time it is called.
1const fn = () => chainable.range(5) 2// Note the function calls below... 3console.log([...fn()]) // prints [0, 1, 2, 3, 4] 4console.log([...fn()]) // prints [0, 1, 2, 3, 4] because a new iterator was used
To use a generator function that creates a sequence, use chainable as a function.
1// A simple generator function 2const fn = function * (length) { 3 for (let i = 0; i < length; i++) { 4 yield i 5 } 6} 7// be sure to call the generator, don't just pass the function 8const a = chainable(fn(3)) 9console.log([...a]) // prints [0, 1, 2]
To use a generator that transforms a sequence, use mapWith
.
1// An example generator that transforms another sequence. 2const fn = function * (n, iterable) { 3 for (let x of iterable) { 4 yield n * x 5 } 6} 7const input = [0, 1, 2, 3, 4] 8// mapWith only accepts generator functions that have one parameter: iterable. 9// If your generator takes additional parameters beyond iterable, you need 10// to wrap it with another function that takes only one parameter. Like this: 11const wrapper = (iterable) => fn(3, iterable) 12const a = chainable(input).mapWith(wrapper).toArray() 13console.log(a) // prints [0, 3, 6, 9, 12]
You can potentially reduce bundle size by importing the generators and function you want to use directly.
1import { zip, zipAll } from 'iterablefu/src/generators.js' 2import { filter, flatten, map } from 'iterablefu/src/transfroms.js' 3import { reduce } from 'iterablefu/src/reducers.js'
If you want a reduced size chainable object, use makeChainableIterable with the
directly imported functions. Customization is covered more completely in the makeChainableIterable
docs.
1// using the imports from above 2import { makeChainableIterable } from 'iterablefu/src/makechainable.js' 3const generators = { zip, zipAll } 4const transforms = { filter, flatten, map } 5const reducers = { reduce } 6const chainable = makeChainableIterable(generators, transforms, reducers)
Customization is covered in the makeChainableIterable documentation.
There are lots of alternatives:
IterableFu
. Does not use ES6 modules.IterableFu
. Typescript.... and many more.
Contributions are welcome. Please create a pull request.
I use pnpm instead of npm.
Automated browser tests use electron. Automated package tests build a *.tgz
package and run tweaked unit tests in a temporary directory. Use pnpm run build
to run everything in the right order.
This project uses Github issues.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
42 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More