Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ describe('List', () => {
expect(r).toBe(v);
});

it('ensures iter is unmodified', () => {
const v = List.of(1, 2, 3);
const r = v.map((value, index, iter) => {
return iter.get(index - 1);
});
expect(r.toArray()).toEqual([3, 1, 2]);
});

it('filters values', () => {
const v = List.of('a', 'b', 'c', 'd', 'e', 'f');
const r = v.filter((value, index) => index % 2 === 1);
Expand Down
6 changes: 6 additions & 0 deletions __tests__/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ describe('Map', () => {
expect(r).toBe(m);
});

it('ensures iter is unmodified', () => {
const m = Map({ a: 1, b: 1 });
const r = m.map((value, key, iter) => 2 * iter.get(key));
expect(r.toObject()).toEqual({ a: 2, b: 2 });
});

it('filters values', () => {
const m = Map({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 });
const r = m.filter(value => value % 2 === 1);
Expand Down
2 changes: 1 addition & 1 deletion src/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class List extends IndexedCollection {
map(mapper, context) {
return this.withMutations(list => {
for (let i = 0; i < this.size; i++) {
list.set(i, mapper.call(context, list.get(i), i, list));
list.set(i, mapper.call(context, list.get(i), i, this));
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class Map extends KeyedCollection {
map(mapper, context) {
return this.withMutations(map => {
map.forEach((value, key) => {
map.set(key, mapper.call(context, value, key, map));
map.set(key, mapper.call(context, value, key, this));
});
});
}
Expand Down