-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.emu
44 lines (43 loc) · 2.17 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!doctype html>
<meta charset="utf8">
<pre class="metadata">
title: Iterator Sequencing
status: proposal
stage: 2
contributors: Michael Ficarra
location: https://tc39.es/proposal-iterator-sequencing/
copyright: false
</pre>
<emu-clause id="sec-iterator.concat">
<h1>Iterator.concat ( ..._items_ )</h1>
<emu-alg>
1. Let _closure_ be a new Abstract Closure with no parameters that captures _items_ and performs the following steps when called:
1. Repeat, while _items_ is not empty,
1. Let _iter_ be the first element of _items_.
1. Remove the first element from _items_.
1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_iter_, ~iterate-strings~).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
1. Let _innerValue_ be ? IteratorStepValue(_iteratorRecord_).
1. If _innerValue_ is ~done~, then
1. Set _innerAlive_ to *false*.
1. Else,
1. Let _completion_ be Completion(Yield(_innerValue_)).
1. If _completion_ is an abrupt completion, then
1. Set _completion_ to Completion(IteratorClose(_iteratorRecord_, _completion_)).
1. Repeat, while _items_ is not empty,
1. Let _trailingIter_ be the first element of _items_.
1. Remove the first element from _items_.
1. If _trailingIter_ is an Object, then
1. Let _nextMethod_ be Completion(Get(_trailingIter_, "next")).
1. If _nextMethod_ is an abrupt completion, then
1. If _completion_ is not a throw completion, set _completion_ to _nextMethod_.
1. Else,
1. Set _nextMethod_ to ! _nextMethod_.
1. If IsCallable(_nextMethod_), then
1. Let _record_ be the Iterator Record { [[Iterator]]: _iter_, [[NextMethod]]: _nextMethod_, [[Done]]: true }.
1. Set _completion_ to Completion(IteratorClose(_iteratorRecord_, _completion_)).
1. Return ? _completion_.
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « »).
</emu-alg>
</emu-clause>