├── .github └── workflows │ ├── build.yml │ └── deploy.yml ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── biblios ├── iterator-helpers.json └── joint-iteration.json ├── package.json └── spec.emu /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build spec 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v3 11 | - uses: ljharb/actions/node/install@main 12 | name: 'nvm install lts/* && npm install' 13 | with: 14 | node-version: lts/* 15 | - run: npm run build 16 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy gh-pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: ljharb/actions/node/install@main 15 | name: 'nvm install lts/* && npm install' 16 | with: 17 | node-version: lts/* 18 | - run: npm run build 19 | - uses: JamesIves/github-pages-deploy-action@v4.3.3 20 | with: 21 | branch: gh-pages 22 | folder: build 23 | clean: true 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # Only apps should have lockfiles 40 | yarn.lock 41 | package-lock.json 42 | npm-shrinkwrap.json 43 | pnpm-lock.yaml 44 | 45 | # Build directory 46 | build 47 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 ECMA TC39 and contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # proposal-array-zip 2 | 3 | A TC39 proposal to synchronize the iteration of multiple arrays. 4 | 5 | This proposal is based entirely on https://github.com/tc39/proposal-joint-iteration - in other words, this proposal is `Iterator.zip` and `Iterator.zipKeyed` for arrays. 6 | 7 | **Stage**: 1 8 | 9 | **Specification**: https://tc39.es/proposal-array-zip/ 10 | 11 | ## Motivation / Problem 12 | 13 | Despite iterators existing for over a decade, it is still exceedingly common to use - and prefer - arrays over iterators, especially for small finite lists. They're simpler to work with, often more performant, and more broadly compatible with ecosystem libraries. 14 | 15 | One can now always turn any iterator into an array with `.toArray()` - which is useful, but not ergnomic, especially when combined with the need to wrap the value in `Iterator.from()` before accessing iterator helpers. 16 | 17 | ## Solution 18 | 19 | Add `Array.zip` and `Array.zipKeyed` static methods to the `Array` constructor. 20 | 21 | ### Rationales 22 | 23 | - the method names, APIs, and semantics must match https://github.com/tc39/proposal-joint-iteration, to avoid confusion 24 | - this includes accepting iterables, like `Array.from` and `Array.fromAsync` 25 | - Adding Array.prototype methods is the most frequent cause of web compatibility issues, and browsers have expressed an unwillingness to even attempt adding more in the future - thus, they must be static 26 | -------------------------------------------------------------------------------- /biblios/iterator-helpers.json: -------------------------------------------------------------------------------- 1 | {"location":"https://tc39.es/proposal-iterator-helpers","entries":[{"type":"table","id":"table-7","number":1,"caption":"Table 1: Well-Known Intrinsic Objects"},{"type":"clause","id":"sec-well-known-intrinsic-objects","aoid":null,"title":"Well-Known Intrinsic Objects","titleHTML":"Well-Known Intrinsic Objects","number":"1"},{"type":"op","aoid":"SetterThatIgnoresPrototypeProperties","refId":"sec-SetterThatIgnoresPrototypeProperties","kind":"abstract operation","signature":{"parameters":[{"name":"_this_","type":{"kind":"opaque","type":"an ECMAScript language value"}},{"name":"_home_","type":{"kind":"opaque","type":"an Object"}},{"name":"_p_","type":{"kind":"opaque","type":"a property key"}},{"name":"_v_","type":{"kind":"opaque","type":"an ECMAScript language value"}}],"optionalParameters":[],"return":{"kind":"completion","completionType":"mixed","typeOfValueIfNormal":{"kind":"unused"}}},"effects":["user-code"]},{"type":"clause","id":"sec-SetterThatIgnoresPrototypeProperties","aoid":"SetterThatIgnoresPrototypeProperties","title":"SetterThatIgnoresPrototypeProperties ( this, home, p, v )","titleHTML":"SetterThatIgnoresPrototypeProperties ( this, home, p, v )","number":"2.1"},{"type":"op","aoid":"GetIteratorDirect","refId":"sec-getiteratordirect","kind":"abstract operation","signature":{"parameters":[{"name":"_obj_","type":{"kind":"opaque","type":"an Object"}}],"optionalParameters":[],"return":{"kind":"completion","completionType":"mixed","typeOfValueIfNormal":{"kind":"opaque","type":"an Iterator Record"}}},"effects":["user-code"]},{"type":"clause","id":"sec-getiteratordirect","aoid":"GetIteratorDirect","title":"GetIteratorDirect ( obj )","titleHTML":"GetIteratorDirect ( obj )","number":"2.2.1"},{"type":"op","aoid":"GetIteratorFlattenable","refId":"sec-getiteratorflattenable","kind":"abstract operation","signature":{"parameters":[{"name":"_obj_","type":{"kind":"opaque","type":"an ECMAScript language value"}},{"name":"_stringHandling_","type":{"kind":"union","types":[{"kind":"opaque","type":"~iterate-strings~"},{"kind":"opaque","type":"~reject-strings~"}]}}],"optionalParameters":[],"return":{"kind":"completion","completionType":"mixed","typeOfValueIfNormal":{"kind":"opaque","type":"an Iterator Record"}}},"effects":["user-code"]},{"type":"clause","id":"sec-getiteratorflattenable","aoid":"GetIteratorFlattenable","title":"GetIteratorFlattenable ( obj, stringHandling )","titleHTML":"GetIteratorFlattenable ( obj, stringHandling )","number":"2.2.2"},{"type":"clause","id":"sec-operations-on-iterator-objects","aoid":null,"title":"Operations on Iterator Objects","titleHTML":"Operations on Iterator Objects","number":"2.2"},{"type":"clause","id":"sec-abstract-operations","aoid":null,"title":"Abstract Operations","titleHTML":"Abstract Operations","number":"2"},{"type":"term","term":"Iterator","refId":"sec-iterator-constructor"},{"type":"term","term":"%Iterator%","refId":"sec-iterator-constructor"},{"type":"clause","id":"sec-iterator","aoid":null,"title":"Iterator ( )","titleHTML":"Iterator ( )","number":"3.1.1.1.1"},{"type":"clause","id":"sec-iterator-constructor","aoid":null,"title":"The Iterator Constructor","titleHTML":"The Iterator Constructor","number":"3.1.1.1"},{"type":"clause","id":"sec-iterator.prototype","aoid":null,"title":"Iterator.prototype","titleHTML":"Iterator.prototype","number":"3.1.1.2.1"},{"type":"term","term":"%WrapForValidIteratorPrototype%","refId":"sec-wrapforvaliditeratorprototype-object"},{"type":"clause","id":"sec-wrapforvaliditeratorprototype.next","aoid":null,"title":"%WrapForValidIteratorPrototype%.next ( )","titleHTML":"%WrapForValidIteratorPrototype%.next ( )","number":"3.1.1.2.2.1.1"},{"type":"clause","id":"sec-wrapforvaliditeratorprototype.return","aoid":null,"title":"%WrapForValidIteratorPrototype%.return ( )","titleHTML":"%WrapForValidIteratorPrototype%.return ( )","number":"3.1.1.2.2.1.2"},{"type":"clause","id":"sec-wrapforvaliditeratorprototype-object","aoid":null,"title":"The %WrapForValidIteratorPrototype% Object","titleHTML":"The %WrapForValidIteratorPrototype% Object","number":"3.1.1.2.2.1"},{"type":"clause","id":"sec-iterator.from","aoid":null,"title":"Iterator.from ( O )","titleHTML":"Iterator.from ( O )","number":"3.1.1.2.2"},{"type":"clause","id":"sec-properties-of-the-iterator-constructor","aoid":null,"title":"Properties of the Iterator Constructor","titleHTML":"Properties of the Iterator Constructor","number":"3.1.1.2"},{"type":"clause","id":"sec-iterator-objects","aoid":null,"title":"Iterator Objects","titleHTML":"Iterator Objects","number":"3.1.1"},{"type":"term","term":"%IteratorHelperPrototype%","refId":"sec-%iteratorhelperprototype%-object"},{"type":"clause","id":"sec-%iteratorhelperprototype%.next","aoid":null,"title":"%IteratorHelperPrototype%.next ( )","titleHTML":"%IteratorHelperPrototype%.next ( )","number":"3.1.2.1.1"},{"type":"clause","id":"sec-%iteratorhelperprototype%.return","aoid":null,"title":"%IteratorHelperPrototype%.return ( )","titleHTML":"%IteratorHelperPrototype%.return ( )","number":"3.1.2.1.2"},{"type":"clause","id":"sec-%iteratorhelperprototype%-@@tostringtag","aoid":null,"title":"%IteratorHelperPrototype% [ @@toStringTag ]","titleHTML":"%IteratorHelperPrototype% [ @@toStringTag ]","number":"3.1.2.1.3"},{"type":"clause","id":"sec-%iteratorhelperprototype%-object","aoid":null,"title":"The %IteratorHelperPrototype% Object","titleHTML":"The %IteratorHelperPrototype% Object","number":"3.1.2.1"},{"type":"clause","id":"sec-iterator-helper-objects","aoid":null,"title":"Iterator Helper Objects","titleHTML":"Iterator Helper Objects","number":"3.1.2"},{"type":"term","term":"Iterator prototype object","refId":"sec-iteratorprototype"},{"type":"term","term":"%Iterator.prototype%","refId":"sec-iteratorprototype"},{"type":"clause","id":"sec-get-iteratorprototype-constructor","aoid":null,"title":"get Iterator.prototype.constructor","titleHTML":"get Iterator.prototype.constructor","number":"3.1.3.1.1"},{"type":"clause","id":"sec-set-iteratorprototype-constructor","aoid":null,"title":"set Iterator.prototype.constructor","titleHTML":"set Iterator.prototype.constructor","number":"3.1.3.1.2"},{"type":"clause","id":"sec-iteratorprototype.constructor","aoid":null,"title":"Iterator.prototype.constructor","titleHTML":"Iterator.prototype.constructor","number":"3.1.3.1"},{"type":"clause","id":"sec-iteratorprototype.map","aoid":null,"title":"Iterator.prototype.map ( mapper )","titleHTML":"Iterator.prototype.map ( mapper )","number":"3.1.3.2"},{"type":"clause","id":"sec-iteratorprototype.filter","aoid":null,"title":"Iterator.prototype.filter ( predicate )","titleHTML":"Iterator.prototype.filter ( predicate )","number":"3.1.3.3"},{"type":"clause","id":"sec-iteratorprototype.take","aoid":null,"title":"Iterator.prototype.take ( limit )","titleHTML":"Iterator.prototype.take ( limit )","number":"3.1.3.4"},{"type":"clause","id":"sec-iteratorprototype.drop","aoid":null,"title":"Iterator.prototype.drop ( limit )","titleHTML":"Iterator.prototype.drop ( limit )","number":"3.1.3.5"},{"type":"clause","id":"sec-iteratorprototype.flatmap","aoid":null,"title":"Iterator.prototype.flatMap ( mapper )","titleHTML":"Iterator.prototype.flatMap ( mapper )","number":"3.1.3.6"},{"type":"clause","id":"sec-iteratorprototype.reduce","aoid":null,"title":"Iterator.prototype.reduce ( reducer [ , initialValue ] )","titleHTML":"Iterator.prototype.reduce ( reducer [ , initialValue ] )","number":"3.1.3.7"},{"type":"clause","id":"sec-iteratorprototype.toarray","aoid":null,"title":"Iterator.prototype.toArray ( )","titleHTML":"Iterator.prototype.toArray ( )","number":"3.1.3.8"},{"type":"clause","id":"sec-iteratorprototype.foreach","aoid":null,"title":"Iterator.prototype.forEach ( fn )","titleHTML":"Iterator.prototype.forEach ( fn )","number":"3.1.3.9"},{"type":"clause","id":"sec-iteratorprototype.some","aoid":null,"title":"Iterator.prototype.some ( predicate )","titleHTML":"Iterator.prototype.some ( predicate )","number":"3.1.3.10"},{"type":"clause","id":"sec-iteratorprototype.every","aoid":null,"title":"Iterator.prototype.every ( predicate )","titleHTML":"Iterator.prototype.every ( predicate )","number":"3.1.3.11"},{"type":"clause","id":"sec-iteratorprototype.find","aoid":null,"title":"Iterator.prototype.find ( predicate )","titleHTML":"Iterator.prototype.find ( predicate )","number":"3.1.3.12"},{"type":"clause","id":"sec-get-iteratorprototype-@@tostringtag","aoid":null,"title":"get Iterator.prototype [ @@toStringTag ]","titleHTML":"get Iterator.prototype [ @@toStringTag ]","number":"3.1.3.13.1"},{"type":"clause","id":"sec-set-iteratorprototype-@@tostringtag","aoid":null,"title":"set Iterator.prototype [ @@toStringTag ]","titleHTML":"set Iterator.prototype [ @@toStringTag ]","number":"3.1.3.13.2"},{"type":"clause","id":"sec-iteratorprototype-@@tostringtag","aoid":null,"title":"Iterator.prototype [ @@toStringTag ]","titleHTML":"Iterator.prototype [ @@toStringTag ]","number":"3.1.3.13"},{"type":"clause","id":"sec-iteratorprototype","aoid":null,"title":"Iterator.prototype","titleHTML":"Iterator.prototype","number":"3.1.3"},{"type":"clause","id":"sec-iteration","aoid":null,"title":"Iteration","titleHTML":"Iteration","number":"3.1"},{"type":"clause","id":"sec-control-abstraction-objects","aoid":null,"title":"Control Abstraction Objects","titleHTML":"Control Abstraction Objects","number":"3"},{"type":"op","aoid":"CreateIteratorFromClosure","refId":"sec-createiteratorfromclosure","kind":"abstract operation","signature":{"parameters":[{"name":"_closure_","type":{"kind":"opaque","type":"an Abstract Closure with no parameters"}},{"name":"_generatorBrand_","type":{"kind":"union","types":[{"kind":"opaque","type":"a String"},{"kind":"opaque","type":"~empty~"}]}},{"name":"_generatorPrototype_","type":{"kind":"opaque","type":"an Object"}}],"optionalParameters":[{"name":"_extraSlots_","type":{"kind":"list","elements":{"kind":"opaque","type":"names of internal slots"}}}],"return":{"kind":"opaque","type":"a Generator"}},"effects":[]},{"type":"clause","id":"sec-createiteratorfromclosure","aoid":"CreateIteratorFromClosure","title":"CreateIteratorFromClosure ( closure, generatorBrand, generatorPrototype [ , extraSlots ] )","titleHTML":"CreateIteratorFromClosure ( closure, generatorBrand, generatorPrototype [ , extraSlots ] )","number":"4.1"},{"type":"clause","id":"updated-abstract-operations","aoid":null,"title":"Updated Abstract Operations","titleHTML":"Updated Abstract Operations","number":"4"}]} -------------------------------------------------------------------------------- /biblios/joint-iteration.json: -------------------------------------------------------------------------------- 1 | {"location":"https://tc39.es/proposal-joint-iteration/","entries":[{"type":"clause","id":"sec-iterator.zip","aoid":null,"title":"Iterator.zip ( iterables [ , options ] )","titleHTML":"Iterator.zip ( iterables [ , options ] )","number":"1"},{"type":"clause","id":"sec-iterator.zipkeyed","aoid":null,"title":"Iterator.zipKeyed ( iterables [ , options ] )","titleHTML":"Iterator.zipKeyed ( iterables [ , options ] )","number":"2"},{"type":"op","aoid":"IteratorZip","refId":"sec-IteratorZip","kind":"abstract operation","signature":{"parameters":[{"name":"_iters_","type":{"kind":"list","elements":{"kind":"opaque","type":"Iterator Records"}}},{"name":"_mode_","type":{"kind":"union","types":[{"kind":"opaque","type":"*\"shortest\"*"},{"kind":"opaque","type":"*\"longest\"*"},{"kind":"opaque","type":"*\"strict\"*"}]}},{"name":"_padding_","type":{"kind":"list","elements":{"kind":"opaque","type":"ECMAScript language values"}}},{"name":"_finishResults_","type":{"kind":"opaque","type":"an Abstract Closure that takes a List of ECMAScript values and returns an ECMAScript value"}}],"optionalParameters":[],"return":{"kind":"opaque","type":"a Generator"}},"effects":[]},{"type":"clause","id":"sec-IteratorZip","aoid":"IteratorZip","title":"IteratorZip ( iters, mode, padding, finishResults )","titleHTML":"IteratorZip ( iters, mode, padding, finishResults )","number":"3"},{"type":"op","aoid":"IteratorCloseAll","refId":"sec-closeall","kind":"abstract operation","signature":{"parameters":[{"name":"_iters_","type":{"kind":"list","elements":{"kind":"opaque","type":"Iterator Records"}}},{"name":"_completion_","type":{"kind":"completion","typeOfValueIfNormal":null,"completionType":"mixed"}}],"optionalParameters":[],"return":{"kind":"completion","typeOfValueIfNormal":null,"completionType":"mixed"}},"effects":["user-code"]},{"type":"clause","id":"sec-closeall","aoid":"IteratorCloseAll","title":"IteratorCloseAll ( iters, completion )","titleHTML":"IteratorCloseAll ( iters, completion )","number":"4"},{"type":"op","aoid":"IfAbruptCloseIterators","refId":"sec-ifabruptcloseiterators","signature":null,"effects":["user-code"]},{"type":"clause","id":"sec-ifabruptcloseiterators","aoid":"IfAbruptCloseIterators","title":"IfAbruptCloseIterators ( value, iteratorRecords )","titleHTML":"IfAbruptCloseIterators ( value, iteratorRecords )","number":"5"},{"type":"clause","id":"sec-%iteratorhelperprototype%.return","aoid":null,"title":"%IteratorHelperPrototype%.return ( )","titleHTML":"%IteratorHelperPrototype%.return ( )","number":"6"},{"type":"op","aoid":"GetOptionsObject","refId":"sec-getoptionsobject","kind":"abstract operation","signature":{"parameters":[{"name":"_options_","type":{"kind":"opaque","type":"an ECMAScript language value"}}],"optionalParameters":[],"return":{"kind":"completion","completionType":"mixed","typeOfValueIfNormal":{"kind":"opaque","type":"an Object"}}},"effects":[]},{"type":"clause","id":"sec-getoptionsobject","aoid":"GetOptionsObject","title":"GetOptionsObject ( options )","titleHTML":"GetOptionsObject ( options )","number":"7.1"},{"type":"clause","id":"stolen-infra","aoid":null,"title":"Infra","titleHTML":"Infra","number":"7"}]} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "template-for-proposals", 4 | "description": "A repository template for ECMAScript proposals.", 5 | "scripts": { 6 | "start": "npm run build-loose -- --watch", 7 | "build": "npm run build-loose -- --strict", 8 | "build-loose": "node -e 'fs.mkdirSync(\"build\", { recursive: true })' && ecmarkup --load-biblio @tc39/ecma262-biblio --verbose spec.emu build/index.html --lint-spec --load-biblio=./biblios/iterator-helpers.json --load-biblio=./biblios/joint-iteration.json" 9 | }, 10 | "homepage": "https://github.com/tc39/template-for-proposals#readme", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/tc39/template-for-proposals.git" 14 | }, 15 | "license": "MIT", 16 | "devDependencies": { 17 | "@tc39/ecma262-biblio": "^2.1.2775", 18 | "ecmarkup": "^20.0.0" 19 | }, 20 | "engines": { 21 | "node": ">= 12" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spec.emu: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
  7 | title: Array.zip
  8 | stage: 1
  9 | contributors: Jordan Harband
 10 | 
11 | 12 | 13 |

Array Objects

14 | 15 | 16 |

The Array Constructor

17 | 18 | 19 |

Properties of the Array Constructor

20 | 21 | 22 |

Array.zip ( _iterables_ [ , _options_ ] )

23 |

This method performs the following steps when called:

24 | 25 | 1. If _iterables_ is not an Object, throw a *TypeError* exception. 26 | 1. Set _options_ to ? GetOptionsObject(_options_). 27 | 1. Let _mode_ be ? Get(_options_, *"mode"*). 28 | 1. If _mode_ is *undefined*, set _mode_ to *"shortest"*. 29 | 1. If _mode_ is not one of *"shortest"*, *"longest"*, or *"strict"*, throw a *TypeError* exception. 30 | 1. Let _paddingOption_ be *undefined*. 31 | 1. If _mode_ is *"longest"*, then 32 | 1. Set _paddingOption_ to ? Get(_options_, *"padding"*). 33 | 1. If _paddingOption_ is not *undefined* and _paddingOption_ is not an Object, throw a *TypeError* exception. 34 | 1. Let _iters_ be a new empty List. 35 | 1. Let _padding_ be a new empty List. 36 | 1. Let _inputIter_ be ? GetIterator(_iterables_, ~sync~). 37 | 1. Let _next_ be ~not-started~. 38 | 1. Repeat, while _next_ is not ~done~, 39 | 1. Set _next_ to Completion(IteratorStepValue(_inputIter_)). 40 | 1. IfAbruptCloseIterators(_next_, _iters_). 41 | 1. If _next_ is not ~done~, then 42 | 1. Let _iter_ be Completion(GetIteratorFlattenable(_next_, ~reject-strings~)). 43 | 1. IfAbruptCloseIterators(_iter_, the list-concatenation of « _inputIter_ » and _iters_). 44 | 1. Append _iter_ to _iters_. 45 | 1. Let _iterCount_ be the number of elements in _iters_. 46 | 1. If _mode_ is *"longest"*, then 47 | 1. If _paddingOption_ is *undefined*, then 48 | 1. Perform the following steps _iterCount_ times: 49 | 1. Append *undefined* to _padding_. 50 | 1. Else, 51 | 1. Let _paddingIter_ be Completion(GetIterator(_paddingOption_, ~sync~)). 52 | 1. IfAbruptCloseIterators(_paddingIter_, _iters_). 53 | 1. If _paddingIter_ is a String, throw a *TypeError* exception. 54 | 1. Let _usingIterator_ be *true*. 55 | 1. Perform the following steps _iterCount_ times: 56 | 1. If _usingIterator_ is *true*, then 57 | 1. Set _next_ to Completion(IteratorStepValue(_paddingIter_)). 58 | 1. IfAbruptCloseIterators(_next_, _iters_). 59 | 1. If _next_ is ~done~, then 60 | 1. Set _usingIterator_ to *false*. 61 | 1. Else, 62 | 1. Append _next_ to _padding_. 63 | 1. If _usingIterator_ is *false*, append *undefined* to _padding_. 64 | 1. If _usingIterator_ is *true*, then 65 | 1. Let _completion_ be Completion(IteratorClose(_paddingIter_, ReturnCompletion(*undefined*))). 66 | 1. IfAbruptCloseIterators(_completion_, _iters_). 67 | 1. Let _finishResults_ be a new Abstract Closure with parameters (_results_) that captures nothing and performs the following steps when called: 68 | 1. Return CreateArrayFromList(_results_). 69 | 1. Let _gen_ be IteratorZip(_iters_, _mode_, _padding_, _finishResults_). 70 | 1. Let _items_ be a new empty List. 71 | 1. Repeat, 72 | 1. Let _value_ be ? IteratorStepValue(_gen_). 73 | 1. If _value_ is ~done~, return CreateArrayFromList(_items_). 74 | 1. Append _value_ to _items_. 75 | 76 |
77 | 78 | 79 |

Array.zipKeyed ( _iterables_ [ , _options_ ] )

80 |

This method performs the following steps when called:

81 | 82 | 1. If _iterables_ is not an Object, throw a *TypeError* exception. 83 | 1. Set _options_ to ? GetOptionsObject(_options_). 84 | 1. Let _mode_ be ? Get(_options_, *"mode"*). 85 | 1. If _mode_ is *undefined*, set _mode_ to *"shortest"*. 86 | 1. If _mode_ is not one of *"shortest"*, *"longest"*, or *"strict"*, throw a *TypeError* exception. 87 | 1. Let _paddingOption_ be *undefined*. 88 | 1. If _mode_ is *"longest"*, then 89 | 1. Set _paddingOption_ to ? Get(_options_, *"padding"*). 90 | 1. If _paddingOption_ is not *undefined* and _paddingOption_ is not an Object, throw a *TypeError* exception. 91 | 1. Let _iters_ be a new empty List. 92 | 1. Let _padding_ be a new empty List. 93 | 1. Let _allKeys_ be ? _iterables_.[[OwnPropertyKeys]](). 94 | 1. Let _keys_ be a new empty List. 95 | 1. For each element _key_ of _allKeys_, do 96 | 1. Let _desc_ be ? _iterables_.[[GetOwnProperty]](_key_). 97 | 1. If _desc_ is not *undefined* and _desc_.[[Enumerable]] is *true*, then 98 | 1. Let _value_ be *undefined*. 99 | 1. If IsDataDescriptor(_desc_) is *true*, then 100 | 1. Set _value_ to _desc_.[[Value]]. 101 | 1. Else, 102 | 1. Assert: IsAccessorDescriptor(_desc_) is *true*. 103 | 1. Let _getter_ be _desc_.[[Get]]. 104 | 1. If _getter_ is not *undefined*, then 105 | 1. Let _getterResult_ be Completion(Call(_getter_, _iterables_)). 106 | 1. IfAbruptCloseIterators(_getterResult_, _iters_). 107 | 1. Set _value_ to _getterResult_. 108 | 1. If _value_ is not *undefined*, then 109 | 1. Append _key_ to _keys_. 110 | 1. Let _iter_ be Completion(GetIteratorFlattenable(_value_, ~reject-strings~)). 111 | 1. IfAbruptCloseIterators(_iter_, _iters_). 112 | 1. Append _iter_ to _iters_. 113 | 1. Let _iterCount_ be the number of elements in _iters_. 114 | 1. If _mode_ is *"longest"*, then 115 | 1. If _paddingOption_ is *undefined*, then 116 | 1. Perform the following steps _iterCount_ times: 117 | 1. Append *undefined* to _padding_. 118 | 1. Else, 119 | 1. For each element _key_ of _keys_, do 120 | 1. Let _value_ be Completion(Get(_paddingOption_, _key_)). 121 | 1. IfAbruptCloseIterators(_value_, _iters_). 122 | 1. Append _value_ to _padding_. 123 | 1. Let _finishResults_ be a new Abstract Closure with parameters (_results_) that captures _keys_ and _iterCount_ and performs the following steps when called: 124 | 1. Let _obj_ be OrdinaryObjectCreate(*null*). 125 | 1. For each integer _i_ such that 0 ≤ _i_ < _iterCount_, in ascending order, do 126 | 1. Perform ! CreateDataPropertyOrThrow(_obj_, _keys_[_i_], _results_[_i_]). 127 | 1. Return _obj_. 128 | 1. Let _gen_ be IteratorZip(_iters_, _mode_, _padding_, _finishResults_). 129 | 1. Let _items_ be a new empty List. 130 | 1. Repeat, 131 | 1. Let _value_ be ? IteratorStepValue(_gen_). 132 | 1. If _value_ is ~done~, return CreateArrayFromList(_items_). 133 | 1. Append _value_ to _items_. 134 | 135 |
136 |
137 |
138 |
139 | --------------------------------------------------------------------------------