Options
All
  • Public
  • Public/Protected
  • All
Menu

Data stream

remarks

DataStream offers an always up to date stream of items from a DataSet or DataView. That means that the stream is evaluated at the time of iteration, conversion to another data type or when cache is called, not when the DataStream was created. Multiple invocations of for example toItemArray may yield different results (if the data source like for example DataSet gets modified).

Type Parameters

  • Item

    The item type this stream is going to work with.

Hierarchy

  • DataStream

Implements

  • Iterable<[Id, Item]>

Index

Constructors

  • new DataStream<Item>(pairs: Iterable<[Id, Item]>): DataStream<Item>
  • Create a new data stream.

    Type Parameters

    • Item

    Parameters

    • pairs: Iterable<[Id, Item]>

      The id, item pairs.

    Returns DataStream<Item>

Properties

_pairs: any

Methods

  • [iterator](): IterableIterator<[Id, Item]>
  • Return an iterable of key, value pairs for every entry in the stream.

    Returns IterableIterator<[Id, Item]>

  • Cache the items from this stream.

    remarks

    This method allows for items to be fetched immediatelly and used (possibly multiple times) later. It can also be used to optimize performance as DataStream would otherwise reevaluate everything upon each iteration.

    Example

    const ds = new DataSet([…])

    const cachedStream = ds.stream()
    .filter(…)
    .sort(…)
    .map(…)
    .cached(…) // Data are fetched, processed and cached here.

    ds.clear()
    chachedStream // Still has all the items.

    Returns DataStream<Item>

    A new DataStream with cached items (detached from the original DataSet).

  • distinct<T>(callback: ((item: Item, id: Id) => T)): Set<T>
  • Get the distinct values of given property.

    Type Parameters

    • T

      The type of the distinct value.

    Parameters

    • callback: ((item: Item, id: Id) => T)

      The function that picks and possibly converts the property.

        • (item: Item, id: Id): T
        • Parameters

          • item: Item
          • id: Id

          Returns T

    Returns Set<T>

    A set of all distinct properties.

  • entries(): IterableIterator<[Id, Item]>
  • Return an iterable of key, value pairs for every entry in the stream.

    Returns IterableIterator<[Id, Item]>

  • filter(callback: ((item: Item, id: Id) => boolean)): DataStream<Item>
  • Filter the items of the stream.

    Parameters

    • callback: ((item: Item, id: Id) => boolean)

      The function that decides whether an item will be included.

        • (item: Item, id: Id): boolean
        • Parameters

          • item: Item
          • id: Id

          Returns boolean

    Returns DataStream<Item>

    A new data stream with the filtered items.

  • forEach(callback: ((item: Item, id: Id) => boolean)): void
  • Execute a callback for each item of the stream.

    Parameters

    • callback: ((item: Item, id: Id) => boolean)

      The function that will be invoked for each item.

        • (item: Item, id: Id): boolean
        • Parameters

          • item: Item
          • id: Id

          Returns boolean

    Returns void

  • keys(): IterableIterator<Id>
  • Return an iterable of keys in the stream.

    Returns IterableIterator<Id>

  • map<Mapped>(callback: ((item: Item, id: Id) => Mapped)): DataStream<Mapped>
  • Map the items into a different type.

    Type Parameters

    • Mapped

      The type of the item after mapping.

    Parameters

    • callback: ((item: Item, id: Id) => Mapped)

      The function that does the conversion.

        • (item: Item, id: Id): Mapped
        • Parameters

          • item: Item
          • id: Id

          Returns Mapped

    Returns DataStream<Mapped>

    A new data stream with the mapped items.

  • max(callback: ((item: Item, id: Id) => number)): null | Item
  • Get the item with the maximum value of given property.

    Parameters

    • callback: ((item: Item, id: Id) => number)

      The function that picks and possibly converts the property.

        • (item: Item, id: Id): number
        • Parameters

          • item: Item
          • id: Id

          Returns number

    Returns null | Item

    The item with the maximum if found otherwise null.

  • min(callback: ((item: Item, id: Id) => number)): null | Item
  • Get the item with the minimum value of given property.

    Parameters

    • callback: ((item: Item, id: Id) => number)

      The function that picks and possibly converts the property.

        • (item: Item, id: Id): number
        • Parameters

          • item: Item
          • id: Id

          Returns number

    Returns null | Item

    The item with the minimum if found otherwise null.

  • reduce<T>(callback: ((accumulator: T, item: Item, id: Id) => T), accumulator: T): T
  • Reduce the items into a single value.

    Type Parameters

    • T

      The type of the accumulated value.

    Parameters

    • callback: ((accumulator: T, item: Item, id: Id) => T)

      The function that does the reduction.

        • (accumulator: T, item: Item, id: Id): T
        • Parameters

          • accumulator: T
          • item: Item
          • id: Id

          Returns T

    • accumulator: T

      The initial value of the accumulator.

    Returns T

    The reduced value.

  • sort(callback: ((itemA: Item, itemB: Item, idA: Id, idB: Id) => number)): DataStream<Item>
  • Sort the items.

    Parameters

    • callback: ((itemA: Item, itemB: Item, idA: Id, idB: Id) => number)

      Item comparator.

        • (itemA: Item, itemB: Item, idA: Id, idB: Id): number
        • Parameters

          • itemA: Item
          • itemB: Item
          • idA: Id
          • idB: Id

          Returns number

    Returns DataStream<Item>

    A new stream with sorted items.

  • toEntryArray(): [Id, Item][]
  • Return an array containing all the entries in this stream.

    remarks

    The array may contain duplicities.

    Returns [Id, Item][]

    The array with all entries from this stream.

  • toIdArray(): Id[]
  • Return an array containing all the ids in this stream.

    remarks

    The array may contain duplicities.

    Returns Id[]

    The array with all ids from this stream.

  • toIdSet(): Set<Id>
  • Return a set containing all the (unique) ids in this stream.

    Returns Set<Id>

    The set of all ids from this stream.

  • toItemArray(): Item[]
  • Return an array containing all the items in this stream.

    remarks

    The array may contain duplicities.

    Returns Item[]

    The array with all items from this stream.

  • toItemSet(): Set<Item>
  • Return a set containing all the (unique) items in this stream.

    Returns Set<Item>

    The set of all items from this stream.

  • toMap(): Map<Id, Item>
  • Return a map containing all the items in this stream accessible by ids.

    Returns Map<Id, Item>

    The map of all id → item pairs from this stream.

  • toObjectMap(): Record<Id, Item>
  • Return an object map containing all the items in this stream accessible by ids.

    remarks

    In case of duplicate ids (coerced to string so 7 == '7') the last encoutered appears in the returned object.

    Returns Record<Id, Item>

    The object map of all id → item pairs from this stream.

  • values(): IterableIterator<Item>
  • Return an iterable of values in the stream.

    Returns IterableIterator<Item>

Generated using TypeDoc