Returns the element type of a Genable
Returns the union of the element types of a tuple of generators.
a tuple type of Genable's.
Any Generator
, Iterator
, or Iterable
, which can be coerced to a
EnhancedGenerator.
Extract the value type being iterated over. I can be an iterator type or an iterable type, synchronous or asynchronous.
A function which can be supplied to a reduce method.
For the case where an init value of type A will be supplied, use:
For the case where no init value will be supplied, use:
For cases where an init value may or may not be supplied:
For cases where A = T (for example, reducing a set of numbers to a number):
The accumulated result.
The individual element values supplied to be reduced.
the initial value for the reducer. If no init value is supplied, the first call will be T; otherwise it will be A.
either Sync or Async.
Selector type to select the types for synchronous or asynchronous generators. Reference the members as Sync.type or Async.type
Delay for the specified number of milliseconds.
Wrap a function in a catch block.
Called when an error is thrown. The return value is returned. If not supplied, undefined is returned.
async generator function eventToGenerator
(queue) returns [generator, controller]
Create a generator that can be made to return values to be supplied by a callback.
send(
value)
: send the next value to generate.end()
: Cause the generator to endthrow(
error)
: Cause the generator to throw an exception.clear()
: Remove any pending queue items.
end
and throw
are synchronous with the queue. That is, they cause the queue to end or throw
when the consumer of the generator has read everything prior in the queue.
queue should return a Queue object that implements .length
, .push()
, .shift()
, and .clear()
.
The default implementation is Denque, which is fast for unbounded size.
The returned generator may be enhanced with {@link Async_.enhance|Async.enhance} if desired.
Other QueueFactory functions provided:
Predicate/type guard to determine if an object is (or looks like, structurally) a AsyncGenerator.
Predicate/type guard, returns true
if the argument satisfies the AsyncIterable
protocol (has a [Symbol.asyncIterator]
method).
Predicate/type guard, returns true
if the argument satisfies the AsyncIterable
protocol (has a [Symbol.asyncIterator]
method) and the AsyncIterator
protocol (a next() method).
Predicate/type guard, returns true
if the argument satisfies the AsyncIterator
protocol (has a next()
method).
Note: There is no way to statically distinguish between an Iterator
and an AsyncIterator
. You will get
runtime errors if you don't anticipate the distinction.
Predicate/type guard to determine if an object is (or looks like, structurally) a Generator.
Predicate/type guard, returns true
if the argument satisfies the Iterable
protocol (has a [Symbol.iterator]
method).
Predicate/type guard, returns true
if the argument satisfies the Iterable
protocol (has a [Symbol.iterator]
method) and the Iterator
protocol (a next() method).
Predicate/type guard, returns true
if the argument satisfies the Iterator
protocol (has a next()
method).
Note: There is no way to statically distinguish between an Iterator
and an AsyncIterator
. You will get
runtime errors if you don't anticipate the distinction.
A QueueFactory that returns a Queue of maximum length 1, which discards older values.
Make a QueueFactory that returns a Queue of maximum length n, which discards older values.
the number of entries, default = 1
.
Make a QueueFactory that returns a Queue of maximum length n, which discards newer values.
the number of entries, default = 1
.
A QueueFactory that returns a Queue of maximum length 1, which discards older values, but returns the last seen forever (until cleared).
function queueUnique({newest, keyFn}): () =>
Return a QueueFactory, which supplies Queue instances that discard already-enqueued entries. Values can be re-enqueued once delivered.
false
(the default), values are dequeued in the order they were first enqueued. Using {newest: true}
deprioritizes more active values so less-busy items can get through. But in a sustained-busy situation, there is no guarantee they will ever be delivered. This can be an advantage or disadvantage, depending on requirements.===
.Accepts objects, and returns just the fields that have changed (are no longer ===
).
This does not distinguish between deleted keys and keys assigned a value of undefined
in the input.
In the output, a deleted key is represented as present with a value of undefined
.
The initial value
Produce numbers from start to end incremented by step. Step may be positive or negative, but not zero.
Produces an EnhancedGenerator.
(default = 0)
(default = Number.MAX_SAFE_INTEGER
)
(default = 1)
Coerce an object to an object that can act as a async generator (that is, satisfy both Iterator
and Iterable
).
If it is an AsyncIterator
but not AsyncIterable
, or AsyncIterable
but not AsyncIterator
,
it is wrapped in an async generator. This generator is not enhanced. Use Async.enhance on the result if
you need an enhanced generator.
Coerce a Genable object to AsyncIterable
. If it is already an AsyncIterable
, it is returned
unchanged. If it is an AsyncIterator
, it is wrapped in an object with a [Symbol.asyncIterator]
method that returns the supplied iterator.
Similar to toAsyncGenerator, but does not require the presence of AsyncGenerator.return
or
AsyncGenerator.throw
methods.
Coerce an object to an object that can act as a generator (that is, satisfy both Iterator
and Iterable
).
If it is an Iterator
but not Iterable
, or Iterable
but not Iterator
, it is wrapped
in a generator. This generator is not enhanced. Use Sync.enhance on the result if
you need an enhanced generator.
Coerce a Genable object to Iterable
. If it is already an Iterable
, it is returned
unchanged. If it is an Iterator
, it is wrapped in an object with a [Symbol.iterator]
method that returns the supplied iterator.
Similar to toGenerator, but does not require the presence of Generator.return
or Generator.throw
methods.
Generated using TypeDoc
Load the full system with a single import.