Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

fix(ExIterable): specialized map should not take over index from filter #693

Merged
merged 1 commit into from
Jun 25, 2016
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
7 changes: 4 additions & 3 deletions src/client/script/lib/ExIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ class FilterMapIterator<S, T> implements Iterator<T> {
private _filter: FilterFn<S>;
private _selector: MapFn<S, T>;
private _index: number;
private _selectorIndex: number;

constructor(source: Iterator<S>, filter: FilterFn<S>, selector: MapFn<S, T>) {
this._source = source;
this._filter = filter;
this._selector = selector;
this._index = 0;
this._selectorIndex = 0;
}

next(): IteratorResult<T> {
Expand All @@ -240,10 +242,9 @@ class FilterMapIterator<S, T> implements Iterator<T> {
let next: IteratorResult<S> = source.next();

while (!next.done) {
let i = this._index++;
const ok: boolean = filter(next.value, i);
const ok: boolean = filter(next.value, this._index++);
if (ok) {
const value = this._selector(next.value, i);
const value = this._selector(next.value, this._selectorIndex++);
return {
done: false,
value,
Expand Down
2 changes: 1 addition & 1 deletion src/client/script/lib/test/test_ExIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe('ExIterable', function () {
});

it('expected the following map()\'s index sequence', function () {
assert.deepStrictEqual(mapSeqOfFilter, [0, 2, 4]);
assert.deepStrictEqual(mapSeqOfFilter, [0, 1, 2]);
});
});
});
Expand Down