Wondering what’s next for npm?Check out our public roadmap! »

    @virtualstate/union
    TypeScript icon, indicating that this package has built-in type declarations

    2.4.7 • Public • Published

    union

    Take a set of async iterations and turn them into an array of the latest values for that iterator.

    This is the general function signature to achieve this:

    export type Input<T> = AsyncIterable<T> | Iterable<T>;
    export type UnionInput<T> = Input<Input<T>>;
    export async function *union<T>(input: UnionInput<T>): AsyncIterable<(T | undefined)[]> {

    This allows us to take multiple functions producing values and group an update set together.

    import { union } from "@virtualstate/union";
    
    for await (const set of union([[1, 2, 3, 4], [5, 6, 7, 8, 9]])) {
        console.log(set);
    }

    The above logs:

    [ 1, 5 ]
    [ 2, 6 ]
    [ 3, 7 ]
    [ 4, 8 ]
    [ 4, 9 ]
    

    Install

    npm i @virtualstate/union

    DownloadsWeekly Downloads

    556

    Version

    2.4.7

    License

    MIT

    Unpacked Size

    129 kB

    Total Files

    64

    Last publish

    Collaborators

    • avatar