itertools

TypeScript port of Python's awesome itertools stdlib.

MIT License

Downloads
13K
Stars
145
Committers
11

Bot releases are hidden (Show)

itertools - v2.3.2 Latest Release

Published by nvie 5 months ago

  • Fix missing top-level exports for izipLongest3 and intersperse
itertools - v2.3.1

Published by nvie 7 months ago

  • Actually export the new itertool at the top level
itertools - v2.3.0

Published by nvie 7 months ago

  • Add new dupes(iterable, keyFn?) function, which returns groups of all duplicate items in iterable.
itertools - v2.2.5

Published by nvie 8 months ago

  • Add missing export for repeat
itertools - v2.2.4

Published by nvie 8 months ago

  • Type output types of all itertools more precisely
itertools - v2.2.3

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! 🙏

itertools - v2.2.2

Published by nvie 9 months ago

  • Fix reduce() bug where using it on a lazy iterable would produce the wrong result (thanks for finding, @quangloc99 🙏!)
itertools - v2.2.1

Published by nvie 10 months ago

  • Fix islice() regression where it wasn't stopping on infinite iterables (thanks for finding, @Kareem-Medhat 🙏!)
itertools - v2.2.0

Published by nvie 10 months ago

  • Move to ESM by default
  • Drop support for node 12.x and 14.x
    (they probably still work, but they're EoL)
itertools - v2.1.2

Published by nvie over 1 year ago

Improve tree-shakability when used in bundlers.

itertools - v2.1.1

Published by nvie over 1 year ago

  • Improve documentation
  • Fix a minor edge case bug in reduce() (when first argument in iterable is undefined, and the predicate function was not explicitly set)
itertools - v2.1.0

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

itertools - v2.0.0

Published by nvie over 1 year ago

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[^1]
  • Drop Node 10.x support
  • 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! 🙏

itertools - v2.0.0-beta1

Published by nvie over 1 year ago

Breaking changes:

  • icompact, compact, and compactObject functions will now also remove
    null values, not only undefined
  • Support only Node >= 12.x
  • Support only TypeScript versions >= 4.3
  • Drop Flow support

Changes:

  • Modern ESM and CJS dual exports
  • Rewrite the source code in TypeScript
itertools - v1.7.1

Published by nvie about 3 years ago

  • Add missing re-export of islice at the top level
itertools - v1.7.0

Published by nvie over 3 years ago

  • TypeScript support!
  • Declare official support for Node 16.x
  • Drop support for Node 13.x (unstable release)
itertools - v1.6.1

Published by nvie about 4 years ago

  • Include an error code with every FlowFixMe suppression (Flow 0.132.x compatibility)
itertools - v1.6.0

Published by nvie almost 5 years ago

itertools - v1.5.4

Published by nvie almost 5 years ago

  • Export roundrobin() at the top level
itertools - v1.5.3

Published by nvie almost 5 years ago

  • Fix bug in chunked() when input is exactly dividable