Skip to content

Commit

Permalink
fixes #5: stop supporting string inputs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra authored Aug 16, 2024
1 parent 7a0247b commit de8d646
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ copyright: false
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 _iteratorRecord_ be ? GetIteratorFlattenable(_iter_, ~reject-strings~).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
1. Let _innerValue_ be ? IteratorStepValue(_iteratorRecord_).
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ if (typeof Iterator === 'undefined' || Iterator == null) {
globalThis.Iterator = function() {};
}

const IteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([].values()))

function getIteratorFlattenable<A>(obj: IteratorOrIterable<A>, stringHandling: 'iterate-strings' | 'reject-strings'): Iterator<A>
function getIteratorFlattenable(obj: any, stringHandling: 'iterate-strings' | 'reject-strings'): Iterator<unknown>
function getIteratorFlattenable(obj: any, stringHandling: 'iterate-strings' | 'reject-strings'): Iterator<unknown> {
Expand Down Expand Up @@ -44,10 +42,10 @@ function* concatImpl(...iterators: Array<unknown>): Generator<unknown> {
try {
for (; i < iterators.length; ++i) {
let iter = iterators[i];
yield* liftIterator(getIteratorFlattenable(iter, 'iterate-strings'));
yield* liftIterator(getIteratorFlattenable(iter, 'reject-strings'));
}
} finally {
let err = null, hasErr = false;;
let err = null, hasErr = false;
for (++i; i < iterators.length; ++i) {
try {
let obj = iterators[i];
Expand Down
11 changes: 6 additions & 5 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ test('concat', async t => {
);
});

test('concat iterates strings', async t => {
assert.deepEqual(
Array.from(Iterator.concat("ab", "cd")),
["a", "b", "c", "d"],
test('concat does not iterate strings', async t => {
let it = Iterator.concat("ab", "cd");
assert.throws(
() => Array.from(it),
TypeError,
);
});

Expand Down Expand Up @@ -142,4 +143,4 @@ test('closes later iterators', async t => {
concatted.return();
assert.deepEqual(returned, ['a', 'b', 'c']);
});
});
});

0 comments on commit de8d646

Please sign in to comment.