Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ES standard for iterator fmethod reuse #1867

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions __tests__/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ describe('List', () => {
]);
});

it('has the same iterator function for values', () => {
const l = List(['a', 'b', 'c']);
expect(l[Symbol.iterator]).toBe(l.values);
});

it('push inserts at highest index', () => {
const v0 = List.of('a', 'b', 'c');
const v1 = v0.push('d', 'e', 'f');
Expand Down
5 changes: 5 additions & 0 deletions __tests__/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ describe('Map', () => {
]);
});

it('has the same iterator function for entries', () => {
const m = Map({ a: 'A', b: 'B', c: 'C' });
expect(m[Symbol.iterator]).toBe(m.entries);
});

it('merges two maps', () => {
const m1 = Map({ a: 'A', b: 'B', c: 'C' });
const m2 = Map({ wow: 'OO', d: 'DD', b: 'BB' });
Expand Down
6 changes: 6 additions & 0 deletions __tests__/Set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ describe('Set', () => {
]);
});

it('has the same iterator function for keys and values', () => {
const s = Set([1, 2, 3]);
expect(s[Symbol.iterator]).toBe(s.keys);
expect(s[Symbol.iterator]).toBe(s.values);
});

it('unions two sets', () => {
const s1 = Set.of('a', 'b', 'c');
const s2 = Set.of('d', 'b', 'wow');
Expand Down
12 changes: 7 additions & 5 deletions src/CollectionImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,16 @@ mixin(SetCollection, {
},
});

SetCollection.prototype.has = CollectionPrototype.includes;
SetCollection.prototype.contains = SetCollection.prototype.includes;
const SetCollectionPrototype = SetCollection.prototype;
SetCollectionPrototype.has = CollectionPrototype.includes;
SetCollectionPrototype.contains = SetCollectionPrototype.includes;
SetCollectionPrototype.keys = SetCollectionPrototype.values;

// Mixin subclasses

mixin(KeyedSeq, KeyedCollection.prototype);
mixin(IndexedSeq, IndexedCollection.prototype);
mixin(SetSeq, SetCollection.prototype);
mixin(KeyedSeq, KeyedCollectionPrototype);
mixin(IndexedSeq, IndexedCollectionPrototype);
mixin(SetSeq, SetCollectionPrototype);

// #pragma Helper functions

Expand Down