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 Sync.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 Sync.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 a synchronous generator. Only a type, not a value.
Given an abstract 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 MySyncIterable implements Iterable<number> {
*[Symbol.iterator]() {
yield 1;
yield 2;
yield 3;
}
}
class MyEnhancedSyncIterable extends Sync.Mixin(MySyncIterable) {
constructor() {
super();
}
}
const foo = new MyEnhancedSyncIterable();
foo.map(i => i * 2).asArray(); // => [2, 4, 6]
foo.map(i => i + 2).asArray(); // => [3, 4, 5]
a constructor for a class that implements Iterable
.
a new constructor for an enhanced class.
See [[Enhancements.asArray]]
Returns: Sync.Generator
Return a generator concatenating this with the supplied generator(s).
See [[Enhancements.concat]]
Returns: Sync.Generator
Convert any Iterator
or Iterable
to a Sync.Generator.
Returns: Sync.Generator
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.every]]
See [[Enhancements.filter]]
Returns: Sync.Generator
See [[Enhancements.filter]]
Returns: Sync.Generator
See [[Enhancements.filter]]
Returns: Sync.Generator
See [[Enhancements.filter]]
Returns: Sync.Generator
See [[Enhancements.filter]]
Returns: Sync.Generator
See [[Enhancements.flat]]
Returns: Sync.Generator
See [[Enhancements.flat]]
Returns: Sync.Generator
See [[Enhancements.flat]]
Returns: Sync.Generator
See [[Enhancements.flat]]
Returns: Sync.Generator
See [[Enhancements.flatMap]]
Returns: Sync.Generator
See [[Enhancements.flatMap]]
Returns: Sync.Generator
See [[Enhancements.flatMap]]
Returns: Sync.Generator
See [[Enhancements.flatMap]]
Returns: Sync.Generator
See [[Enhancements.flatMap]]
Returns: Sync.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: Sync.Generator
See [[Enhancements.limit]]
Returns: Sync.Generator
See [[Enhancements.map]]
Returns: Sync.Generator
See [[Enhancements.map]]
Returns: Sync.Generator
See [[Enhancements.map]]
Returns: Sync.Generator
See [[Enhancements.map]]
Returns: Sync.Generator
Create an Sync.Generator which yields the supplied values.
Returns: Sync.Generator
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.reduce]]
See [[Enhancements.repeat]]
Returns: Sync.Generator
See [[Enhancements.repeatLast]]
Returns: Sync.Generator
See [[Enhancements.slice]]
Returns: Sync.Generator
See [[Enhancements.slice]]
Returns: Sync.Generator
See [[Enhancements.slice]]
Returns: Sync.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 Iterator<T>
into an Iterable<T>
object which can be repeatedly
iterated over, invoking the function each time to produce a new Iterator<T>
.
A function that returns an Iterator<T>
Arguments to be passed to the function
See [[Enhancements.zip]]
Returns: Sync.Generator
Generated using TypeDoc
Namespace for the aynchronous version of the generic generator operators.