- Fix: allow dynamic
minCostfunction call onchunkedByCost, for dynamic cost functions that change over time. - Packaging fix: no longer trigger pnpm's "Ignored build scripts" warning in consumer projects.
- New custom helper:
chunkedByCost(items, costOf, maxCost, minCost?), groups a stream of items into chunks bounded by a hardmaxCostcap and an optionalminCostsoft target. - Drop support for Node 20.x (it probably still works, but it's EoL)
- Add new
xrange, which is likerangebut returns an array directly instead of an iterable.
- New itertools:
groupByandindexBy - Renamed
groupbytoigroupby - Deprecated
groupby(now an alias toigroupby) - Drop support for Node 18.x (it probably still works, but it's EoL)
- Use
bundlermodule resolution setting (recommended setting for libraries that use a bundler) - Upgrade dev dependencies
- Add second param
indexto all predicates. This will make operations like partitioning a list based on the element position as easy as partitioning based on the element value, for example:const items = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const [thirds, rest] = partition(items, (item, index) => index % 3 === 0); console.log(thirds); // [1, 4, 7] console.log(rest); // [2, 3, 5, 6, 8, 9]
- Officially drop Node 16 support (it may still work)
- Fix missing top-level exports for
izipLongest3andintersperse
- Actually export the new itertool at the top level
- Add new
dupes(iterable, keyFn?)function, which returns groups of all duplicate items in iterable.
- Add missing export for
repeat
- Type output types of all itertools more precisely
Fixes a bug where some iterators would render an inputted generator unusable, causing it to no longer be consumable after the iterable returns.
Example:
function* gen() {
yield 1;
yield 2;
yield 3;
yield 4;
}
const lazy = gen();
// [1, 2]
Array.from(islice(lazy, 0, 2));
Array.from(lazy);
// ❌ Previously: []
// ✅ Now correctly: [3, 4]This bug only happened when the source was a generator. It did not happen on a normal iterable.
Similar bugs were present in:
find()islice()takewhile()dropwhile()
No other iterables were affected by this bug. This is the same bug that was
fixed in 2.2.2 for reduce(), so many thanks again for surfacing this edge
case, @quangloc99! 🙏
- Fix
reduce()bug where using it on a lazy generator would produce the wrong result (thanks for finding, @quangloc99 🙏!)
- Fix
islice()regression where it wasn't stopping on infinite iterables (thanks for finding, @Kareem-Medhat 🙏!)
- Move to ESM by default
- Drop support for node 12.x and 14.x
(they probably still work, but they're EoL)
- Improve tree-shakability when used in bundlers
- Improve documentation
- Fix a bug in
reduce()in a very small edge case
The following functions retain richer type information about their arguments:
ifilter()filter()partition()
For example, TypeScript will now know the following:
const items = [3, "hi", -7, "foo", 13];
function isNum(value: unknown): value is number {
return typeof value === "number";
}
const numbers: number[] = filter(items, isNum); // ✅
const [numbers, strings] = partition(items, isNum); // ✅
// ^^^^^^^ ^^^^^^^ string[]
// number[]-
Add new
find(iterable, pred)function, which is almost the same asfirst(iterable, pred)but behaves slightly more intuitive in the case where no predicate function is given. -
Fix bug in
chunked()withsize=1
Breaking changes:
- Rewritten source code in TypeScript (instead of Flow)
- Modern ESM and CJS dual exports (fully tree-shakable when using ESM)
- Massively reduced bundle size
- Targeted ES2015 (instead of ES5)
- Support only TypeScript versions >= 4.3
- Drop Flow support*
- Drop Node 10.x support
icompact,compact, andcompactObjectfunctions will now also removenullvalues, not onlyundefined
(*: I'm still open to bundling Flow types within this package, but only if
that can be supported in a maintenance-free way, for example by using a script
that will generate *.flow files from TypeScript source files. If someone can
add support for that, I'm open to pull requests! 🙏 )
- Add missing re-export of
isliceat the top level
- TypeScript support!
- Declare official support for Node 16.x
- Drop support for Node 13.x (unstable release)
- Include an error code with every FlowFixMe suppression (Flow 0.132.x compatibility)
- New itertool:
heads()
- Export
roundrobin()at the top level
- Fix bug in
chunked()when input is exactly dividable
- Export
count()function at the top level 🤦♂️
- Internal change to make the code Flow 0.105.x compatible. Basically stops
using array spreads (
[...things]) in favor ofArray.from().
- Remove direct code dependency on
regenerator-runtime(let@babel/runtimemanage it)
- Switch to Babel 7
- Export
filterat the top level
- New build system
- Cleaner NPM package contents
- Drop support for Node 7
- Make itertools.js fully Flow Strict
- Export
permutations()at the top-level
- Add port of
groupby()function (see #87, thanks @sgenoud!)
- declare library to be side effect free (to help optimize webpack v4 builds)
- Include regenerator runtime via babel-runtime
- Make
regenerator-runtimea normal runtime dependency
- Lower required version of
regenerator-runtime
- Properly declare dependency on
regenerator-runtime
- Fix bug in
cycle()with infinite inputs
Started keeping a CHANGELOG.