Skip to content

Commit 50e5209

Browse files
Fixes #6: don't default chunk/window size to 2 (#9)
1 parent 1eba4ad commit 50e5209

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

spec.emu

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ copyright: false
1010
</pre>
1111

1212
<emu-clause id="sec-iterator.prototype.chunks">
13-
<h1>Iterator.prototype.chunks ( [ _chunkSize_ ] )</h1>
13+
<h1>Iterator.prototype.chunks ( _chunkSize_ )</h1>
1414
<p>This method performs the following steps when called:</p>
1515
<emu-alg>
1616
1. Let _O_ be the *this* value.
1717
1. If _O_ is not an Object, throw a *TypeError* exception.
18-
1. If _chunkSize_ is not present, set _chunkSize_ to *2*<sub>𝔽</sub>.
1918
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.
2019
1. Let _iterated_ be ? GetIteratorDirect(_O_).
2120
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _chunkSize_ and performs the following steps when called:
@@ -35,12 +34,11 @@ copyright: false
3534
</emu-clause>
3635

3736
<emu-clause id="sec-iterator.prototype.windows">
38-
<h1>Iterator.prototype.windows ( [ _windowSize_ ] )</h1>
37+
<h1>Iterator.prototype.windows ( _windowSize_ )</h1>
3938
<p>This method performs the following steps when called:</p>
4039
<emu-alg>
4140
1. Let _O_ be the *this* value.
4241
1. If _O_ is not an Object, throw a *TypeError* exception.
43-
1. If _windowSize_ is not present, set _windowSize_ to *2*<sub>𝔽</sub>.
4442
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.
4543
1. Let _iterated_ be ? GetIteratorDirect(_O_).
4644
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _windowSize_ and performs the following steps when called:

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function* chunksImpl<A>(iter: Iterator<A>, chunkSize: number): Generator<Array<A
1919
}
2020

2121
function chunks<A>(this: Iterator<A>, chunkSize: number): Generator<Array<A>>
22-
function chunks(this: unknown, chunkSize: unknown = 2): Generator<unknown> {
22+
function chunks(this: unknown, chunkSize: unknown): Generator<unknown> {
2323
if (
2424
typeof chunkSize !== 'number'
2525
|| chunkSize <= 0
@@ -45,7 +45,7 @@ function* windowsImpl<A>(iter: Iterator<A>, windowSize: number): Generator<Array
4545
}
4646

4747
function windows<A>(this: Iterator<A>, windowSize: number): Generator<Array<A>>
48-
function windows(this: unknown, windowSize: unknown = 2): Generator<unknown> {
48+
function windows(this: unknown, windowSize: unknown): Generator<unknown> {
4949
if (
5050
typeof windowSize !== 'number'
5151
|| windowSize <= 0

test/index.mjs

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function* nats(limit) {
1212

1313
test('chunks', async t => {
1414
assert.deepEqual(
15-
Array.from(nats(5).chunks()),
15+
Array.from(nats(5).chunks(2)),
1616
[[0, 1], [2, 3], [4]],
1717
);
1818
assert.deepEqual(
@@ -36,6 +36,9 @@ test('chunks', async t => {
3636
[],
3737
);
3838

39+
assert.throws(() => {
40+
nats(1).chunks();
41+
}, RangeError)
3942
assert.throws(() => {
4043
nats(1).chunks([2]);
4144
}, RangeError)
@@ -55,7 +58,7 @@ test('chunks', async t => {
5558

5659
test('windows', async t => {
5760
assert.deepEqual(
58-
Array.from(nats(5).windows()),
61+
Array.from(nats(5).windows(2)),
5962
[[0, 1], [1, 2], [2, 3], [3, 4]],
6063
);
6164
assert.deepEqual(
@@ -75,6 +78,9 @@ test('windows', async t => {
7578
[],
7679
);
7780

81+
assert.throws(() => {
82+
nats(1).windows()
83+
}, RangeError)
7884
assert.throws(() => {
7985
nats(1).windows([2]);
8086
}, RangeError)
@@ -90,4 +96,4 @@ test('windows', async t => {
9096
assert.throws(() => {
9197
nats(1).windows(Math.pow(2, 53));
9298
}, RangeError)
93-
});
99+
});

0 commit comments

Comments
 (0)