TypeScript port of Python's awesome itertools stdlib.
MIT License
Bot releases are visible (Hide)
izipLongest3
and intersperse
Published by nvie 7 months ago
Published by nvie 7 months ago
dupes(iterable, keyFn?)
function, which returns groups of all duplicate items in iterable.Published by nvie 8 months ago
repeat
Published by nvie 8 months ago
Published by nvie 9 months ago
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! 🙏
Published by nvie 9 months ago
reduce()
bug where using it on a lazy iterable would produce the wrong result (thanks for finding, @quangloc99 🙏!)Published by nvie 10 months ago
islice()
regression where it wasn't stopping on infinite iterables (thanks for finding, @Kareem-Medhat 🙏!)Published by nvie 10 months ago
Published by nvie over 1 year ago
Improve tree-shakability when used in bundlers.
Published by nvie over 1 year ago
reduce()
(when first argument in iterable is undefined
, and the predicate function was not explicitly set)Published by nvie over 1 year ago
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 as first(iterable, pred)
but behaves slightly more intuitive in the case where no predicate function is given.
Fix bug in chunked()
with size=1
Published by nvie over 1 year ago
Breaking changes:
icompact
, compact
, and compactObject
functions will now also remove null
values, not only undefined
[^1]: 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! 🙏
Published by nvie over 1 year ago
Breaking changes:
icompact
, compact
, and compactObject
functions will now also removenull
values, not only undefined
Changes:
Published by nvie about 3 years ago
islice
at the top levelPublished by nvie over 3 years ago
Published by nvie about 4 years ago
Published by nvie almost 5 years ago
roundrobin()
at the top levelPublished by nvie almost 5 years ago