Skip to content

Commit

Permalink
feat(concat): accept multiple concat sources
Browse files Browse the repository at this point in the history
  • Loading branch information
jtenner committed Apr 15, 2019
1 parent fb5036e commit 2ee75c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class Sequence<TItem> implements Iterable<TItem> {
* from([1, 2]).concat([3, 4]);
* ```
*/
concat<TOther>(other: Iterable<TOther>): Sequence<TItem | TOther> {
return new Sequence(createConcatIterable(this._iterable, other));
concat<TOther>(...others: Iterable<TOther>[]): Sequence<TItem | TOther> {
return new Sequence(createConcatIterable(this._iterable, ...others));
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/transforms/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { IterableCreatorIterable } from "../IterableCreatorIterable";

export const createConcatIterable = <TItem, TOther>(
source: Iterable<TItem>,
other: Iterable<TOther>
...others: Iterable<TOther>[]
): Iterable<TItem | TOther> =>
new IterableCreatorIterable(function* concat(): IterableIterator<TItem | TOther> {
new IterableCreatorIterable(function* concat(): IterableIterator<
TItem | TOther
> {
for (const item of source) {
yield item;
}

for (const item of other) {
yield item;
for (const other of others) {
for (const item of other) {
yield item;
}
}
});

0 comments on commit 2ee75c7

Please sign in to comment.