Options
All
  • Public
  • Public/Protected
  • All
Menu

Functions to be used in {@link Array.prototype.reduce} as a callback.

see

https://pavel-surinin.github.io/declarativejs/#/?id=reducers

Index

Type aliases

IsMergable

IsMergable<T>: function

Type parameters

  • T

Type declaration

    • (currentValue: T, aggregatorValue: T, key: string): boolean
    • Parameters

      • currentValue: T
      • aggregatorValue: T
      • key: string

      Returns boolean

OnDuplicateFunction

OnDuplicateFunction<K>: function

Type parameters

  • K

Type declaration

    • (v1: K, v2: K, key: string): K | never
    • Parameters

      • v1: K
      • v2: K
      • key: string

      Returns K | never

Functions

ImmutableMap

ImmutableObject

  • ImmutableObject<T>(): Readonly<StringMap<T>>

Map

Const Partition

  • Partition<E>(): [E, E]

Const flat

  • flat<T>(agr: T[], value: T[]): T[]
  • Function to be used in {@link Array.prototype.reduce} as a callback to make from 2d array simple array As second parameter in reduce function need to pass []

    Type parameters

    • T

    Parameters

    • agr: T[]

      to collect in

    • value: T[]

      to concatenate with

    Returns T[]

    concatenated array

groupBy

  • groupBy<T, K>(key: K): function
  • groupBy<T>(getKey: KeyGetter<T>): function
  • groupBy<T, TR>(getKey: KeyGetter<T>, transformer: Getter<T, TR>): function
  • groupBy<T, TR, K>(key: K, transformer: Getter<T, TR>): function
  • Function to be used in {@link Array.prototype.reduce} as a callback to group by provided key. As second parameter in reduce function need to pass Reducer.Map() Reducer.ImmutableMap() Or own implementation of MethodMap

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=groupby

    Type parameters

    • T

    • K: keyof T

    Parameters

    • key: K

      objects key to resolve value,to group by it

    Returns function

  • Groups an array by key resolved from callback. Function to be used in {@link Array.prototype.reduce} as a callback to group by provided function. As second parameter in reduce function need to pass Reducer.Map() Reducer.ImmutableMap() Or own implementation of MethodMap

    throws

    {Error} if resolved key from callback is not a string

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=groupby

    Type parameters

    • T

    Parameters

    • getKey: KeyGetter<T>

      callback to resolve key,to group by it

    Returns function

  • Groups an array by key resolved from callback and transform value to put in new grouped array. Function to be used in {@link Array.prototype.reduce} as a callback to group by provided key. As second parameter in reduce function need to pass {@link Reducer.Map()}, {@link Reducer.ImmutableMap()} or own implementation of MethodMap

    export
    template

    T type of element in array

    template

    TR type of element in grouped array

    throws

    {Error} if resolved key from callback is not a string

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=groupby

    Type parameters

    • T

    • TR

    Parameters

    • getKey: KeyGetter<T>

      function to get key, output must be a string by this key an array will be grouped

    • transformer: Getter<T, TR>

      function to transform array element in grouped array

    Returns function

         function to use in Array.reduce
  • Groups an array by key and transform value to put in new grouped array. Function to be used in {@link Array.prototype.reduce} as a callback to group by provided key. As second parameter in reduce function need to pass {@link Reducer.Map()}, {@link Reducer.ImmutableMap()} or own implementation of MethodMap

    export
    template

    T type of element in array

    template

    TR type of element in grouped array

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=groupby

    Type parameters

    • T

    • TR

    • K: keyof T

    Parameters

    • key: K

      of an element in array object to group by it

    • transformer: Getter<T, TR>

      function to transform array element in grouped array

    Returns function

         function to use in Array.reduce

max

  • max(agr: number, value: number, index: number, array: number[]): number

min

  • min(agr: number, value: number, index: number, array: number[]): number

pairwise

  • pairwise<T>(): _pairwise

partitionBy

  • partitionBy<T>(matches: Predicate<T>): function
  • partitionBy<T, K>(matches: K): function
  • partitionBy<T>(matches: Partial<T>): function
  • Function to be used in {@link Array.prototype.reduce} as a callback. It reduces array in a tuple ([[], []]) with two arrays. First array contains elements, that matches predicate, second array, that does not match. As a second paramter in reduce (callback, initialValue), as an initial value need to pass empty tuple of arrays ([[], []]) Or use Reducer.Partition function to create initial value for it. Predicate is a function that takes current element as a parameter and returns boolean.

    export
    template

    T element type in array

    see

    Reducer.Partition

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=partitionby

    Type parameters

    • T

    Parameters

    • matches: Predicate<T>

      predicate function that has a a value current element and returns boolean

    Returns function

    function to pass to Array.reduce

      • (agr: Tuple<T[], T[]>, value: T): Tuple<T[], T[]>
      • Parameters

        • agr: Tuple<T[], T[]>
        • value: T

        Returns Tuple<T[], T[]>

  • Function to be used in {@link Array.prototype.reduce} as a callback. It reduces array in a tuple ([[], []]) with two arrays. First array contains elements, that matches predicate, second array, that does not match. As a second paramter in reduce (callback, initialValue), as an initial value need to pass empty tuple of arrays ([[], []]) Or use Reducer.Partition function to create initial value for it. Predicate is an objects key, that will be coerced to boolean with Boolean constructor (Boolean()).

    export
    template

    T element type in array

    see

    Reducer.Partition

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=partitionby

    Type parameters

    • T

    • K: keyof T

    Parameters

    • matches: K

      element key, which value is used to decide in which partition array to add element

    Returns function

    function to pass to Array.reduce

      • (agr: Tuple<T[], T[]>, value: T): Tuple<T[], T[]>
      • Parameters

        • agr: Tuple<T[], T[]>
        • value: T

        Returns Tuple<T[], T[]>

  • Function to be used in {@link Array.prototype.reduce} as a callback. It reduces array in a tuple ([[], []]) with two arrays. First array contains elements, that matches predicate, second array, that does not match. As a second paramter in reduce (callback, initialValue), as an initial value need to pass empty tuple of arrays ([[], []]) Or use Reducer.Partition function to create initial value for it. Predicate is an object, which key and values must match current element. For matching all key-value pairs, element will be placed in first partition array.

    export
    template

    T element type in array

    see

    Reducer.Partition

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=partitionby

    Type parameters

    • T

    Parameters

    • matches: Partial<T>

      object to match key value pairs in current element

    Returns function

    function to pass to Array.reduce

      • (agr: Tuple<T[], T[]>, value: T): Tuple<T[], T[]>
      • Parameters

        • agr: Tuple<T[], T[]>
        • value: T

        Returns Tuple<T[], T[]>

scan

  • scan<T, R>(accFunction: function, initial: R): _scan
  • Function to be used in {@link Array.prototype.reduce} as a callback. Applies an accumulator function over the current element and returns each intermediate result for accumulation

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=scan

    Type parameters

    • T

    • R

    Parameters

    • accFunction: function

      accumulator function

        • (acc: R, current: T): R
        • Parameters

          • acc: R
          • current: T

          Returns R

    • initial: R

      value

    Returns _scan

Const sum

  • sum(agr: number, value: number): number
  • Function to be used in {@link Array.prototype.reduce} as a callback. Finds sum of values in array. Array must contain only numbers

    Parameters

    • agr: number
    • value: number

    Returns number

    sum of values in array.

toMap

  • Function to be used in {@link Array.prototype.reduce} as a callback to make a Map. Collects items by key, from callback to {@link MethodMap}. If function resolves key, that already exists it will throw an Error As second parameter in reduce function need to pass Reducer.Map(), Reducer.ImmutableMap(), Or own implementation of MethodMap

    type

    {T} value type

    type

    {R} value type in map

    throws

    Error if resolved key from callback is not a string

    throws

    Error if map has duplicate keys will thrown error

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=tomap

    Type parameters

    • T

    Parameters

    • getKey: KeyGetter<T>

      callback to get key from value

    Returns function

      • Parameters

        • agr: MethodMap<T>

          object to collect in

        • value: T

          value that that is passed in function for each iteration

        • index: number
        • array: T[]

        Returns MethodMap<T>

  • Function to be used in {@link Array.prototype.reduce} as a callback to make a Map. Collects items to {@link MethodMap} by key from callback. If function resolves key, that already exists it will throw an Error. Second callback is value mapper. As second parameter in reduce function need to pass Reducer.Map(), Reducer.ImmutableMap(), Or own implementation of MethodMap

    throws

    {Error} if map has duplicate keys will thrown error

    throws

    {Error} if resolved key from callback is not a string

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=tomap

    Type parameters

    • T

    • K

    Parameters

    • getKey: KeyGetter<T>

      callback to get key from value

    • valueGetter: Getter<T, K>

    Returns function

toMergedObject

  • toMergedObject(isMergable?: IsMergable): _toMergedObject

toObject

  • toObject<T>(getKey: KeyGetter<T>): function
  • toObject<T, K>(getKey: KeyGetter<T>, valueGetter: Getter<T, K>): function
  • toObject<T, K>(getKey: KeyGetter<T>, valueGetter: Getter<T, K>, merge: function): function
  • Function to be used in {@link Array.prototype.reduce} as a callback. Collects items to object by key from callback. If function resolves key, that already exists it will throw an Error As second parameter in reduce function need to pass {} or Reducer.ImmutableObject()

    throws

    {Error} if map has duplicate keys will thrown error

    throws

    {Error} if resolved key from callback is not a string * *

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=toobject

    Type parameters

    • T

    Parameters

    • getKey: KeyGetter<T>

      callback to get key from value

    Returns function

  • Function to be used in {@link Array.prototype.reduce} as a callback Collects items to object by key from callback. If function resolves key, that already exists it will throw an Error. Second callback is value mapper. As second parameter in reduce function need to pass {} or Reducer.ImmutableObject()

    throws

    {Error} if map has duplicate keys will thrown error

    throws

    {Error} if resolved key from callback is not a string *

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=toobject

    Type parameters

    • T

    • K

    Parameters

    • getKey: KeyGetter<T>

      callback to get key from value

    • valueGetter: Getter<T, K>

    Returns function

  • Function to be used in {@link Array.prototype.reduce} as a callback Collects items to object by key from callback. If function resolves key, that already exists it will throw an Error. Second callback is value mapper. As second parameter in reduce function need to pass {} or Reducer.ImmutableObject()

    throws

    {Error} if resolved key from callback is not a string *

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=toobject

    Type parameters

    • T

    • K

    Parameters

    • getKey: KeyGetter<T>

      callback to get key from value

    • valueGetter: Getter<T, K>
    • merge: function

      callback to merge values with duplicate key

        • (v1: K, v2: K): K
        • Parameters

          • v1: K
          • v2: K

          Returns K

    Returns function

unzip

  • unzip<T>(): _unzip
  • Function to be used in {@link Array.prototype.reduce} as a callback. It does the opposite as Reducer.zip or Reducer.zipAll. It collects from all zipped arrays one arrays, that was before zip. Takes from each nested arrays and element and for each index will collect to new array. The length of and array will be the shortest length of arrays to unzip

    export
    see

    Reducer.zip

    see

    Reducer.zipAll

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=unzip

    Type parameters

    • T

    Returns _unzip

    function to use in Array.reduce

zip

  • zip<T1, T2>(array: T2[]): function
  • zip<T1, T2, R>(array: T2[], withFx: function): function
  • Function to be used in {@link Array.prototype.reduce} as a callback. Collects two arrays into one array of tuples, two element array([x ,y]). The length of zipped array will be length of shortest array.

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=zip

    Type parameters

    • T1

    • T2

    Parameters

    • array: T2[]

      array to zip with

    Returns function

    array with elements from two arrays as tuples

      • (agr: Array<Tuple<T1, T2>>, value: T1, index: number): Tuple<T1, T2>[]
      • Parameters

        • agr: Array<Tuple<T1, T2>>
        • value: T1
        • index: number

        Returns Tuple<T1, T2>[]

  • Function to be used in {@link Array.prototype.reduce} as a callback. Collects two arrays into one array of aggregated objects by provided function. The length of zipped array will be length of shortest array.

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=zip

    Type parameters

    • T1

    • T2

    • R

    Parameters

    • array: T2[]

      array to zip with

    • withFx: function

      function that will combine two elements into one

        • (t1: T1, t2: T2): R
        • Parameters

          • t1: T1
          • t2: T2

          Returns R

    Returns function

    array with elements from two arrays

      • (agr: Array<R>, value: T1, index: number): Array<R>
      • Parameters

        • agr: Array<R>
        • value: T1
        • index: number

        Returns Array<R>

zipAll

  • zipAll(...arraysToZip: Array<any>[]): _zipAll
  • Function to be used in {@link Array.prototype.reduce} as a callback. Collects all arrays to arrays of arrays, with elements at being grouped with elements from other arrays by same index. The length of zipped array will be length of shortest array. Almost the same as Reducer.zip, except zipAll accepts multiple array to zip with.

    export
    see

    Reducer.zip

    see

    https://pavel-surinin.github.io/declarativejs/#/?id=zipall

    Parameters

    • Rest ...arraysToZip: Array<any>[]

    Returns _zipAll

    function to use in Array.reduce

Object literals

Const MergeStrategy

MergeStrategy: object

Object merging strategy used in {@link Reducer#toMergedObject}

see

toMergedObject

CHECKED

  • CHECKED(aggregatorValue: any, currentValue: any): boolean
  • Keys in objects may have duplicates, but values in these key must be equal

    Parameters

    • aggregatorValue: any
    • currentValue: any

    Returns boolean

OVERRIDE

  • OVERRIDE(): true
  • Overrides value by duplicated key while merging objects

    Returns true

UNIQUE

  • UNIQUE(aggregatorValue: any): boolean
  • Keys in objects must be unique

    Parameters

    • aggregatorValue: any

    Returns boolean

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc