mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add support for concating iterators
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2b33d5eed6
commit
9da08f4ac4
@ -12,6 +12,7 @@ interface Iterator<T> extends Iterable<T> {
|
|||||||
collect<U>(fn: (values: Iterable<T>) => U): U;
|
collect<U>(fn: (values: Iterable<T>) => U): U;
|
||||||
map<U>(fn: (val: T) => U): Iterator<U>;
|
map<U>(fn: (val: T) => U): Iterator<U>;
|
||||||
flatMap<U>(fn: (val: T) => U[]): Iterator<U>;
|
flatMap<U>(fn: (val: T) => U[]): Iterator<U>;
|
||||||
|
concat(src2: IterableIterator<T>): Iterator<T>;
|
||||||
join(sep?: string): string;
|
join(sep?: string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ export function chain<T>(src: IterableIterator<T>): Iterator<T> {
|
|||||||
find: (fn) => find(src, fn),
|
find: (fn) => find(src, fn),
|
||||||
join: (sep) => join(src, sep),
|
join: (sep) => join(src, sep),
|
||||||
collect: (fn) => fn(src),
|
collect: (fn) => fn(src),
|
||||||
|
concat: (src2) => chain(concat(src, src2)),
|
||||||
[Symbol.iterator]: () => src,
|
[Symbol.iterator]: () => src,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -236,3 +238,13 @@ export function every<T>(src: Iterable<T>, fn: (val: T) => any): boolean {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function* concat<T>(src1: IterableIterator<T>, src2: IterableIterator<T>): IterableIterator<T> {
|
||||||
|
for (const val of src1) {
|
||||||
|
yield val;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const val of src2) {
|
||||||
|
yield val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user