Skip to content

Commit

Permalink
zipWithIndexL 비동기 동작 지원 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
daengdaengLee committed Jan 14, 2021
1 parent b069554 commit f43490b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Lazy/zipWithIndexL.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import go1 from "../Strict/go1.js";
import toIter from "../Strict/toIter.js";

export default function* zipWithIndexL(iter) {
let i = -1;
for (const a of toIter(iter)) yield [++i, a];
for (const a of toIter(iter)) {
const _i = ++i;
yield go1(a, (a) => [_i, a]);
}
}
22 changes: 22 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2750,4 +2750,26 @@ const { expect } = chai;
expect(await last([1, 2, Promise.resolve(3)])).to.eql(3);
});
});

describe(`L.zipWIthIndex`, function () {
it(`Yield each element with index`, function () {
// given
const items = ["a", "b", "c", "d", "e"];

// when
const result = L.zipWithIndex(items);

// then
let cur;
for (let i = 0; i < items.length; i++) {
const item = items[i];
cur = result.next();
expect(cur.done).false;
expect(i).to.equal(cur.value[0]);
expect(item).to.equal(cur.value[1]);
}
cur = result.next();
expect(cur.done).true;
});
});
})();

0 comments on commit f43490b

Please sign in to comment.