Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "xform/partition-sync"

Index

Functions

Const collect

  • collect<T>(cache: Map<PropertyKey, T[]>, currKeys: Set<PropertyKey>): IObjectOf<T>

partitionSync

  • partitionSync<T>(keys: PropertyKey[] | Set<PropertyKey>, opts?: Partial<PartitionSyncOpts<T>>): PartitionSync<T>
  • partitionSync<T>(keys: PropertyKey[] | Set<PropertyKey>, src: Iterable<T>): IterableIterator<IObjectOf<T>>
  • partitionSync<T>(keys: PropertyKey[] | Set<PropertyKey>, opts: Partial<PartitionSyncOpts<T>>, src: Iterable<T>): IterableIterator<IObjectOf<T>>
  • Transducer intended for synchronization and provenance tracking of possibly previously merged inputs. Partitions the input into labeled tuple objects with the object keys obtained from the user provided keyfn (which is applied to each input value).

    remarks

    By default, a new result is only produced once values from all given labeled sources have been received. Only labels contained in the provided key set are used, others are skipped. The result tuples will contain the most recent consumed value from each labeled input. In dataflow scenarios this can be used to ensure a subsequent operation consuming these tuples has all necessary inputs, regardless of the individual rates of change of each original (pre-merge) input.

    If the mergeOnly option is set to true (default: false), no synchronization (waiting) of inputs is applied and potentially partially populated tuple objects will be emitted for each received input value, however as with the default behavior, tuples will retain the most recent consumed value from other inputs.

    Required keys (input ID labels) can be dynamically added or removed via .add(id) or .delete(id) on the returned transducer.

    example
    src = [
      ["a", 1], ["a", 2], ["d", 100], ["b", 10],
      ["b", 11], ["c", 0], ["a", 3]
    ];
    
    // form tuples for values only from sources "a" & "b"
    // here the label is the first element of each input item
    [...partitionSync(["a", "b"], { key: (x) => x[0] }, src)]
    // [ { a: ["a", 2], b: ["b", 10] },
    //   { b: ["b", 11], a: ["a", 3] } ]

    In addition to the default mode of operation, i.e. waiting for new values from all named inputs before a new tuple is produced, the behavior for all but the first tuple can be changed to emit new tuples as soon as a new value with a qualifying label has become available (with other values in the tuple remaining). Compare with above example:

    // passing `false` to disable tuple reset
    [...partitionSync(
      ["a", "b"],
      {
        key: (x) => x[0],
        reset: false
      },
      src
    )]
    // [ { a: ["a", 2], b: ["b", 10] },
    //   { a: ["a", 2], b: ["b", 11] },
    //   { a: ["a", 3], b: ["b", 11] } ]

    By default, the last emitted tuple is allowed to be incomplete (in case the input closed). To only allow complete tuples, set the optional all arg to false.

    Type parameters

    • T

    Parameters

    • keys: PropertyKey[] | Set<PropertyKey>

      allowed label set

    • Optional opts: Partial<PartitionSyncOpts<T>>

    Returns PartitionSync<T>

  • Type parameters

    • T

    Parameters

    • keys: PropertyKey[] | Set<PropertyKey>
    • src: Iterable<T>

    Returns IterableIterator<IObjectOf<T>>

  • Type parameters

    • T

    Parameters

    • keys: PropertyKey[] | Set<PropertyKey>
    • opts: Partial<PartitionSyncOpts<T>>
    • src: Iterable<T>

    Returns IterableIterator<IObjectOf<T>>

Const requiredInputs

  • requiredInputs(required: Set<PropertyKey>, curr: Set<PropertyKey>): boolean

Generated using TypeDoc