Skip to content

[GR-74263] Implement Joint Iteration Proposal #1016

@woess

Description

@woess

TL;DR

Implement the TC39 Joint Iteration proposal (stage 3) in GraalJS.

Proposal: https://github.com/tc39/proposal-joint-iteration
Spec draft: https://tc39.es/proposal-joint-iteration/

Details

This proposal adds two new APIs:

  • Iterator.zip(iterables[, options])
  • Iterator.zipKeyed(iterablesByKey[, options])

These APIs advance multiple iterators in lockstep and produce:

  • arrays for Iterator.zip
  • objects for Iterator.zipKeyed

The options bag supports:

  • mode: "shortest" (default)
  • mode: "longest"
  • mode: "strict"

For "longest", padding values can be provided:

  • as an iterable for Iterator.zip
  • as an object for Iterator.zipKeyed

Example:

Iterator.zip([
  [0, 1, 2],
  [3, 4, 5],
]).toArray();
// => [[0, 3], [1, 4], [2, 5]]

Iterator.zipKeyed({
  a: [0, 1, 2],
  b: [3, 4, 5, 6],
  c: [7, 8, 9],
}, {
  mode: "longest",
  padding: { c: 10 },
}).toArray();
// => [
//      { a: 0,         b: 3, c: 7 },
//      { a: 1,         b: 4, c: 8 },
//      { a: 2,         b: 5, c: 9 },
//      { a: undefined, b: 6, c: 10 },
//    ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalECMAScript Proposals

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions