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)
.
Return all of the values from this generator as an array. You do not want to call this on an infinite generator (for obvious reasons); consider using EnhancedGenerator.slice or EnhancedGenerator.limit to limit the size before calling this.
Concatenates generators (or iterators or iterables).
Ensures that any supplied generators are terminated when this is terminated.
zero or more additional Genable to provide values.
Returns false
and terminates this generator if the predicate is false for any of the generator's
yielded values.
If the generator terminates without having failed the predicate, true
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.
f receives the value and a sequential index.
Optional context to be passed as this
to the predicate.
Flatten the values yielded by this generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
(default = 1)
Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Operate on each value produced by this generator. f is called with two values, the value yielded by this generator and a sequential index.
Value to be supplied as context this
for function f.
Trivial, but handy, same as Array.prototype.join.
(default = ',').
See also EnhancedGenerator.join
Limit the number of values that can be generated. A RangeError
is thrown if this limit is
exceeded. See EnhancedGenerator.slice if you want to truncate.
Apply the function to each value yielded by this generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.
Optional value to be supplied as context this
for function f.
Like Array.prototype.reduce
, but the 3rd argument to the reducing function ("array") is omitted
because there is no array.
Like Array.prototype.reduce
, but the 3rd argument to the reducing function ("array") is omitted
because there is no array.
Returns a new generator that repeats the supplied value after this generator completes.
the value to repeat
The number repetitions; the default is infinite.
Returns a new generator that repeats the last value returned by this (or undefined
if this
did not return any values).
Return a new EnhancedGenerator that only yields the indicated values, skipping start initial values and continuing until the end.
Returns true
and terminates this generator if the predicate is true for any of the generator's
yielded values.
If the generator terminates without having satisfied the predicate, false
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
Combines this generator with additional ones, returning a generator that produces a tuple with each of their results.
Terminates when the first generator terminates. To get other behaviors, use with EnhancedGenerator.repeat or EnhancedGenerator.repeatLast.
Return all of the values from this generator as an array. You do not want to call this on an infinite generator (for obvious reasons); consider using EnhancedGenerator.slice or EnhancedGenerator.limit to limit the size before calling this.
Concatenates generators (or iterators or iterables).
Ensures that any supplied generators are terminated when this is terminated.
zero or more additional Genable to provide values.
Enhance an existing generator (or iterator or iterable) to be a EnhancedGenerator.
Returns false
and terminates the generator if the predicate is false for any of the generator's
yielded values.
If the generator terminates without having failed the predicate, true
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
Returns false
and terminates this generator if the predicate is false for any of the generator's
yielded values.
If the generator terminates without having failed the predicate, true
is returned.
predicate to apply to each yielded value.
Returns false
and terminates this generator if the predicate is false for any of the generator's
yielded values.
If the generator terminates without having failed the predicate, true
is returned.
predicate to apply to each yielded value.
the generator
Returns false
and terminates this generator if the predicate is false for any of the generator's
yielded values.
If the generator terminates without having failed the predicate, true
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
the generator
Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.
f receives the value and a sequential index.
the type of value.
Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.
f receives the value and a sequential index.
the type of value.
Optional context to be passed as this
to the predicate.
a Genable
Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.
f receives the value and a sequential index.
the type of value.
Optional context to be passed as this
to the predicate.
Flatten the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Flatten the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Flatten the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a function that accepts a generator, and returns another generator that yields the individual value at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a function that accepts a generator, and returns another generator that yields the individual value at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.
The return type is currently over-broad
Operate on each value produced by the generator. f is called with two values, the value yielded by this generator and a sequential index.
the type of value produced by the generator.
Optional value to be supplied as context this
for function f.
the generator.
Operate on each value produced by the generator. f is called with two values, the value yielded by this generator and a sequential index.
the type of value produced by the generator.
the generator.
Operate on each value produced by the generator. f is called with two values, the value yielded by this generator and a sequential index.
the type of value produced by the generator.
Optional value to be supplied as context this
for function f.
Operate on each value produced by the generator. f is called with two values, the value yielded by this generator and a sequential index.
the type of value produced by the generator.
Returns a function that joins the elements produced by a Genable, analogous to Array.prototype.join
.
(default = ',')
Joins the elements produced by a Genable, analogous to Array.prototype.join
.
Limit the number of values that can be generated. A RangeError
is thrown if this limit is
exceeded. See EnhancedGenerator.slice if you want to truncate.
Limit the number of values that can be generated. A RangeError
is thrown if this limit is
exceeded. See EnhancedGenerator.slice if you want to truncate.
Apply the function to each value yielded by the generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.
the type of value produced by the generator.
Apply the function to each value yielded by the generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.
the type of value produced by the generator.
Optional value to be supplied as context this
for function f.
Apply the function to each value yielded by the generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.
the type of value produced by the generator.
the generator
Apply the function to each value yielded by the generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.
the type of value produced by the generator.
Optional value to be supplied as context this
for function f.
the generator
Reduces gen like Array.prototype.reduce
, but the 3rd argument to the reducing function ("array")
is omitted because there is no array.
Returns a reducer function that, when applied to a Generator
gen, reduces gen like
Array.prototype.reduce. The 3rd argument to the reducing function ("array")
is omitted because there is no array.
Returns a reducer function that, when applied to a Generator
gen, reduces gen like
Array.prototype.reduce
. The 3rd argument to the reducing function ("array")
is omitted because there is no array.
Reduces gen like Array.prototype.reduce
, but the 3rd argument to the reducing function ("array")
is omitted because there is no array.
Returns a reducer function that, when applied to a Generator
gen, reduces gen like
Array.prototype.reduce
. The 3rd argument to the reducing function ("array")
is omitted because there is no array.
Alternatively, the init value can be supplied along with the generator as a second argument.
Returns a new generator that repeats the supplied value after the supplied generator completes.
the value to repeat
The number repetitions; the default is infinite.
Returns a new generator that repeats the last value returned by gen (or undefined
if gen
did not return any values).
Return a new EnhancedGenerator that only yields the indicated values, skipping start initial values and continuing until the end.
Return a new EnhancedGenerator that only yields the indicated values, skipping start initial values and continuing until the end.
Returns true
and terminates the generator if the predicate is true for any of the generator's
yielded values.
If the generator terminates without having satisfied the predicate, false
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
Returns true
and terminates the generator if the predicate is true for any of the generator's
yielded values.
If the generator terminates without having satisfied the predicate, false
is returned.
predicate to apply to each yielded value.
Returns true
and terminates the generator if the predicate is true for any of the generator's
yielded values.
If the generator terminates without having satisfied the predicate, false
is returned.
predicate to apply to each yielded value.
the generator
Returns true
and terminates the generator if the predicate is true for any of the generator's
yielded values.
If the generator terminates without having satisfied the predicate, false
is returned.
predicate to apply to each yielded value.
Optional value to supply as context (this
) for the predicate
the generator
Combines generators, returning a generator that produces a tuple with each of their results.
Terminates when the first generator terminates. To get other behaviors, use with EnhancedGenerator.repeat or EnhancedGenerator.repeatLast.
Generated using TypeDoc
Utilities to create and use generators which can be manipulated 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
andIterable
objects without first converting to a generator.The EnhancedGenerator.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
andIterable
objects to EnhancedGenerator.For methods which return a EnhancedGenerator, care is take to propagate any
Generator.throw
andGenerator.return
calls to any supplied generators, so they can properly terminate.The exception is EnhancedGenerator.flat (and by extension, EnhancedGenerator.flatMap), which cannot know what nested generators they might encounter in the future. Any generators encountered so far will be terminated, however.