@metreeca/flow - v0.9.21
    Preparing search index...

    Module sinks

    Terminal operations that consume feeds and produce final results.

    Sinks close a pipe: applying one to a Feed triggers execution and returns a promise resolving to the final result. Those that can decide their outcome early stop consuming rather than draining the source, while those collecting items into a container return it deeply immutable, freezing the container together with the items, keys and values collected into it. Those reducing the feed to a single value, whether computed over its items or selected among them, resolve to undefined when the feed carries none and no result is defined, leaving the choice of a fallback to the caller.

    Custom Sinks are functions that consume async iterables by returning a promise for the final result:

    import { pipe } from '@metreeca/flow';
    import { items } from '@metreeca/flow/feeds';
    import type { Sink } from '@metreeca/flow';

    function histogram<V>(): Sink<V, Map<V, number>> {
    return async source => {
    const counts = new Map<V, number>();
    for await (const item of source) { counts.set(item, (counts.get(item) ?? 0)+1); }
    return counts;
    };
    }

    await pipe(
    (items("a", "b", "a"))
    (histogram())
    ); // Map(2) { "a" => 2, "b" => 1 }

    Functions

    avg

    Creates a sink averaging the items of the feed.

    count

    Creates a sink counting the items of the feed.

    every

    Creates a sink reporting whether every item matches a predicate.

    find

    Creates a sink retrieving the first item matching a predicate.

    forEach

    Creates a sink handing every item to a consumer.

    max

    Creates a sink selecting the greatest item of the feed.

    min

    Creates a sink selecting the least item of the feed.

    reduce

    Creates a sink reducing the feed to a single value, with or without an initial value.

    some

    Creates a sink reporting whether some item matches a predicate.

    sum

    Creates a sink summing the items of the feed.

    toArray

    Creates a sink collecting the items of the feed into an array.

    toMap

    Creates a sink collecting items or extracted values into a map under extracted keys.

    toObject

    Creates a sink collecting items or extracted values into a deeply immutable object under extracted keys.

    toSet

    Creates a sink collecting the distinct items of the feed into a set.

    toString

    Creates a sink joining the items of the feed into a string.