-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.emu
61 lines (59 loc) · 3.08 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!doctype html>
<meta charset="utf8">
<pre class="metadata">
title: Iterator Chunking
status: proposal
stage: 1
contributors: Michael Ficarra
location: https://tc39.es/proposal-iterator-chunking/
copyright: false
</pre>
<emu-clause id="sec-iterator.prototype.chunks">
<h1>Iterator.prototype.chunks ( _chunkSize_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. If _O_ is not an Object, throw a *TypeError* exception.
1. If _chunkSize_ is not an integral Number in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), throw a *RangeError* exception.
1. Let _iterated_ be ? GetIteratorDirect(_O_).
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _chunkSize_ and performs the following steps when called:
1. Let _buffer_ be a new empty List.
1. Repeat,
1. Let _value_ be ? IteratorStepValue(_iterated_).
1. If _value_ is ~done~, then
1. If _buffer_ is not empty, then
1. Perform Completion(Yield(CreateArrayFromList(_buffer_))).
1. Return ReturnCompletion(*undefined*).
1. Append _value_ to _buffer_.
1. If the number of elements in _buffer_ is ℝ(_chunkSize_), then
1. Let _completion_ be Completion(Yield(CreateArrayFromList(_buffer_))).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Set _buffer_ to a new empty List.
1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterators]] »).
1. Set _result_.[[UnderlyingIterators]] to « _iterated_ ».
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iterator.prototype.windows">
<h1>Iterator.prototype.windows ( _windowSize_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. If _O_ is not an Object, throw a *TypeError* exception.
1. If _windowSize_ is not an integral Number in the inclusive interval from *1*<sub>𝔽</sub> to 𝔽(2<sup>32</sup> - 1), throw a *RangeError* exception.
1. Let _iterated_ be ? GetIteratorDirect(_O_).
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _windowSize_ and performs the following steps when called:
1. Let _buffer_ be a new empty List.
1. Repeat,
1. Let _value_ be ? IteratorStepValue(_iterated_).
1. If _value_ is ~done~, return ReturnCompletion(*undefined*).
1. Append _value_ to _buffer_.
1. If the number of elements in _buffer_ is ℝ(_windowSize_), then
1. Let _completion_ be Completion(Yield(CreateArrayFromList(_buffer_))).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Remove the first element from _buffer_.
1. Let _result_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterators]] »).
1. Set _result_.[[UnderlyingIterators]] to « _iterated_ ».
1. Return _result_.
</emu-alg>
</emu-clause>