Skip to content

v2.0.0

Choose a tag to compare

@jdesrosiers jdesrosiers released this 14 Nov 07:01
· 4 commits to main since this release

A rewrite of @hyperjump/pact. The documentation is now at https://hyperjump.io/pact/.

What's new

  • Faster. The iterators are hand-written classes instead of generators. Sync pipelines are 2 to 15 times faster than in v1, and async pipelines are about 1.5 times faster. See Benchmarks for how pipelines compare with array methods.
  • compose. It builds a pipeline without a source, which you can use with any number of iterables or put in another pipeline. See Pipelines.
  • New functions. flatMap, forEach, and zipKeyed. range takes a step, and zip takes any number of iterables and has shortest, longest, and strict modes.
  • Native helper methods. Every iterator pact returns is an Iterator, so the native helper methods work on it. See Native helpers.
  • Async iterators read in order and can be disposed. Overlapping next() calls are queued, and every async iterator has [Symbol.asyncDispose](). See Async.

Breaking changes

  • Every function is a step. It takes only its configuration and returns a function that takes the iterable: map(fn, iterable) is map(fn)(iterable), or a step in a pipe. flatten takes only the depth.
  • The root module has only the sync functions. The async ones are in @hyperjump/pact/async, without the async prefix: asyncMap is map from there. The types lost the prefix too.
  • collectArray, collectSet, collectMap, and collectObject are toArray, toSet, toMap, and toObject.
  • zip takes an array of iterables instead of two arguments, and stops when any of them is done. Use { mode: "longest" } to keep going.
  • Callbacks get each value's index as the argument after the value, so map(parseInt) is wrong. Use map((s) => parseInt(s)).
  • reduce without an initial value starts with the first value, and throws a TypeError for an empty iterable.
  • head closes the iterator it reads from.
  • concat throws a TypeError for anything that isn't an iterable object, including a string.
  • A step gets an iterator from its iterable when it's called with it, so something that isn't iterable throws right away.
  • The functions return an IteratorObject instead of a Generator, without a throw() method.
  • It needs Node.js 24 or later, or Chrome 122, Firefox 131, or Safari 18.4 or later. Its types need TypeScript 5.6 or later.

See Migrating from v1 for each change and what to do about it.