import { Enumerable } from "https://deno.land/x/proc@0.22.1/src/enumerable.ts";
Enumerable wrapper for AsyncIterable
.
Use the factory function enumerate to create new instances.
Constructors
Construct a new enumerable wrapper.
Properties
Convert to text lines, grouped into arrays.
For large data or data that is broken into many small lines, this can improve performance over lines.
Take the head of the enumeration.
This operation is equivalent to take(1)
and consumes the enumeration.
Convert to text lines.
Note that this should probably only be used with small data. Consider chunkedLines to improve performance with larger data.
Methods
Map the sequence from one type to another, concurrently.
Results are returned in order. The order of processing is concurrent, and therefore somewhat arbitrary.
Map the sequence from one type to another, concurrently.
Items are iterated out of order. This allows maximum concurrency at all times, but the output order cannot be assumed to be the same as the input order.
This guarantees maximum concurrency whereas concurrentMap does not if the workload isn't balanced. Prefer concurrentUnorderedMap to concurrentMap for best/consistent performance.
Count the number of items; optionally with a filter.
Return true
if every element satisfies the provided testing function.
Filter the sequence to contain just the items that pass a test.
Filter the sequence to exclude the items that pass a test. This returns the inverse of filter.
Return the first element that satisfies the provided testing function, or undefined
if no value satisfies the testing function.
Equivalent to calling map followed by flatten.
Perform an operation for each item in the sequence.
Executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
Executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
Return true
if some element satisfies the provided testing function.
Transform the iterable from one type to another with an opportunity to catch and handle errors.
Unzip a collection of [A, B]
into Enumerable<A>
and Enumerable<B>
.
Note that this operations uses tee, so it will use memory during the iteration.
Example
const [a, b] = enumerate([[1, "A"], [2, "B"], [3, "C"]]).unzip();
// a is number[] -> [1, 2, 3]
// b is string[] -> ["A", "B", "C"]
Dump output to a writer and close it.
This is a low-level asynchronous write of bytes without locking.
Write all data to the writer.
Example
Write some numbers to stdout
.
range({to: 99})
.map(n => n.toString())
.transform(toBytes)
.writeTo(Deno.stdout.writable, {noclose: true});
Zip two Enumerables together. If collections are unequal length, the longer collection is truncated.
Example
const a = range({ from: 1, until: 3 });
const b = enumerate(["A", "B", "C"]);
const result = a.zip(b);
// [[1, "A"], [2, "B"], [3, "C"]]
Implement AsyncIterable<T>
.