Skip to content

Commit

Permalink
Merge pull request #1 from jsr-core/improve
Browse files Browse the repository at this point in the history
feat: allow mixed iterable in `chain` function
  • Loading branch information
lambdalisue authored Aug 7, 2024
2 parents 27eef2a + 1091927 commit 2f5ea63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion async/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* ```
*/
export async function* chain<T>(
...iterables: Iterable<T>[] | AsyncIterable<T>[]
...iterables: (Iterable<T> | AsyncIterable<T>)[]
): AsyncIterable<T> {
for await (const iterable of iterables) {
for await (const value of iterable) {
Expand Down
11 changes: 11 additions & 0 deletions async/chain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ Deno.test("chain", async (t) => {
assertEquals(await toArray(result), expected);
assertType<IsExact<typeof result, AsyncIterable<number>>>(true);
});

await t.step("with mixed iterable", async () => {
const result = chain(
toAsyncIterable([1, 2]),
[3, 4],
toAsyncIterable([5]),
);
const expected = [1, 2, 3, 4, 5];
assertEquals(await toArray(result), expected);
assertType<IsExact<typeof result, AsyncIterable<number>>>(true);
});
});

0 comments on commit 2f5ea63

Please sign in to comment.