Install
npm install --save extra-generator
yarn add extra-generator
API
handleYieldedValues
function handleYieldedValues<T, Return, Next>(
generator: Generator<T, Return, Next>
, fn: (value: T, index: number) => Next
): Return
handleYieldedValuesAsync
function handleYieldedValuesAsync<T, Return, Next>(
generator: Generator<T, Return, Next>
, fn: (value: T, index: number) => PromiseLike<Next>
): Promise<Return>
function handleYieldedValuesAsync<T, Return, Next>(
generator: AsyncGenerator<T, Return, Next>
, fn: (value: T, index: number) => Awaitable<Next>
): Promise<Return>
of
function of<T>(val: T): IterableIterator<T>
of(1)
repeat
function repeat<T>(val: T, times: number = Infinity): IterableIterator<T>
repeat(1)
repeat(1, 3)
repeat(1, 0)
spawn
function spawn<T>(create: (num: number) => T, times: number = Infinity): IterableIterator<T>
spawn(x => x * 2)
spawn(x => x * 2, 3)
spawn(x => x * 2, 0)
countdown
function countdown(begin: number, end: number): IterableIterator<number>
countdown(2, -2)
countdown(1, 1)
countdown(0, 1)
countup
function countup(begin: number, end: number): IterableIterator<number>
countup(-2, 2)
countup(1, 1)
countup(1, 0)
range
function range(
start: number
, end: number
, step: number = 1
, inclusive: boolean = false
): IterableIterator<number>
range(1, 1)
range(-2, 2)
range(2, -2)
range(1, -1, 0.5)
range(2, -2, 0)
range(2, -2, -0.5)
stringifyJSONStream
function stringifyJSONStream<T>(iterable: Iterable<T>): Iterable<string>
stringifyJSONStreamAsync
function stringifyNDJSONStreamAsync<T>(iterable: AsyncIterable<T>): AsyncIterable<string>
stringifyNDJSONStream
function stringifyNDJSONStream<T>(iterable: Iterable<T>): Iterable<string>
stringifyNDJSONStreamAsync
function stringifyNDJSONStreamAsync<T>(iterable: AsyncIterable<T>): AsyncIterable<string>
timestampBasedId
function timestampBasedId(): Iterator<[timestamp: number, num: number]>
ReusableIterable
interface IReusableIterable<T> extends Iterable<T> {
close(): void
}
class ReusableIterable<T> implements IReusableIterable<T> {
get done(): boolean | undefined
constructor(iterable: Iterable<T>)
close(): void
}
ReusableAsyncIterable
interface IReusableAsyncIterable<T> extends AsyncIterable<T> {
close(): Promise<void>
}
class ReusableAsyncIterable<T> implements IReusableAsyncIterable<T> {
get done(): boolean | undefined
constructor(iterable: AsyncIterable<T>)
close(): Promise<void>
}
ngrams
function ngrams(text: string, n: number): IterableIterator<string>
allNgrams
function allNgrams(text: string): IterableIterator<string>
allCombinations
function allCombinations<T>(arr: T[], k: number): IterableIterator<T[]>
allIndexCombinations
function allIndexCombinations(
arr: unknown[]
, k: number
): IterableIterator<number[]>
positiveFactors
function positiveFactors(value: number): IterableIterator<number>
positiveFactors(0)
positiveFactors(10)
positiveFactors(-10)
positiveCommonDivisors
function positiveCommonDivisors(a: number, b: number): IterableIterator<number>
positiveCommonDivisors(0, 0)
positiveCommonDivisors(12, 8)
positiveCommonDivisors(-12, 8)