An enhanced generator that can be used in various ways.
Most methods come both as instance (prototype) methods and as static methods. They
provide equivalent functionality, but the static methods allow use on Iterator
and
Iterable
objects without first converting to a generator.
The Async.enhance method will add additional instance methods to
an ordinary generator's prototype (a new prototype, not modifying any global prototype!).
It can also be used to convert Iterator
and Iterable
objects to Generator.
For methods which return an Async.Generator, care is take to propagate any Generator.throw
and Generator.return
calls to any supplied generators, so they can properly terminate.
The exceptions are [[Enhancements.flat]] (and by extension, [[Enhancements.flatMap]]), which cannot know what nested generators they might encounter in the future. Any generators encountered so far will be terminated, however.
the type of values returned in the iteration result.
the type of values returned in the iteration result when the generator terminates
the type of value which can be passed to .next(val)
.
See also Sync.Generator
Literal type indicating an asynchronous generator. Only a type, not a value.
Given a class that implements Iterable<T, TReturn, TNext>
, this returns a class that implements IEnhancements, allowing one to treat it as if
it were an array, in supporting methods such as .map() and .filter().
Usage:
class MyAsyncIterable implements AsyncIterable<number> {
async *[Symbol.Asynciterator]() {
yield 1;
yield 2;
yield 3;
}
}
class MyEnhancedAsyncIterable extends Async.Mixin(MyAsyncIterable) {
constructor() {
super();
}
}
const foo = new MyEnhancedAsyncIterable();
await foo.map(i => i * 2).asArray(); // => [2, 4, 6]
await foo.map(i => i + 2).asArray(); // => [3, 4, 5]
a constructor for a class that implements AsyncIterable
.
a new constructor for an enhanced class.
See [[Enhancements.asArray]]
Returns: Async.Generator
Return a generator concatenating this with the supplied generator(s).
See [[Enhancements.concat]]
Returns: Async.Generator
Convert any AsyncIterator
or AsyncIterable
to a Async.Generator.
Returns: Async.Generator
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.filter]]
Returns: Async.Generator
See [[Enhancements.filter]]
Returns: Async.Generator
See [[Enhancements.filter]]
Returns: Async.Generator
See [[Enhancements.filter]]
Returns: Async.Generator
See [[Enhancements.filter]]
Returns: Async.Generator
See [[Enhancements.flat]]
Returns: Async.Generator
See [[Enhancements.flat]]
Returns: Async.Generator
See [[Enhancements.flat]]
Returns: Async.Generator
See [[Enhancements.flat]]
Returns: Async.Generator
See [[Enhancements.flatMap]]
Returns: Async.Generator
See [[Enhancements.flatMap]]
Returns: Async.Generator
See [[Enhancements.flatMap]]
Returns: Async.Generator
See [[Enhancements.flatMap]]
Returns: Async.Generator
See [[Enhancements.flatMap]]
Returns: Async.Generator
See [[Enhancements.forEach]]
See [[Enhancements.forEach]]
See [[Enhancements.forEach]]
See [[Enhancements.forEach]]
See [[Enhancements.join]]
See [[Enhancements.join]]
See [[Enhancements.join]]
See [[Enhancements.limit]]
Returns: Async.Generator
See [[Enhancements.limit]]
Returns: Async.Generator
See [[Enhancements.map]]
Returns: Async.Generator
See [[Enhancements.map]]
Returns: Async.Generator
See [[Enhancements.map]]
Returns: Async.Generator
See [[Enhancements.map]]
Returns: Async.Generator
Create an Async.Generator which yields the supplied values.
Returns: Async.Generator
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.repeat]]
Returns: Async.Generator
See [[Enhancements.repeatLast]]
Returns: Async.Generator
See [[Enhancements.slice]]
Returns: Async.Generator
See [[Enhancements.slice]]
Returns: Async.Generator
See [[Enhancements.slice]]
Returns: Async.Generator
See [[Enhancements.some]]
See [[Enhancements.some]]
See [[Enhancements.some]]
See [[Enhancements.some]]
See [[Enhancements.some]]
See [[Enhancements.sort]]
Turn a function that returns an AsyncIterator<T>
into an AsyncIterable<T>
object which can be repeatedly
iterated over, invoking the function each time to produce a new AsyncIterator<T>
.
A function that returns an AsyncIterator<T>
Arguments to be passed to the function
See [[Enhancements.zip]]
Returns: Async.Generator
Generated using TypeDoc
Namespace for the asynchronous version of the generic generator operators.