geninq
Version:
A JavaScript version of the Linq library for Generators
40 lines (34 loc) • 779 B
text/typescript
import { Build } from "./utils";
declare global {
interface Generator<T = unknown, TReturn = any, TNext = unknown> {
/**
* Converts the sequence into an array.
* @returns The sequence as a type safe array
*/
array(): T[];
}
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> {
/**
* Converts the sequence into an array.
* @returns A promise of the sequence as a type safe array
*/
array(): Promise<T[]>;
}
}
Build(
"array",
function () {
const result: unknown[] = [];
for (const item of this) {
result.push(item);
}
return result;
},
async function () {
const result = [];
for await (const item of this) {
result.push(item);
}
return result;
}
);