Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/group-by/docs/types/index.d"

Index

Type aliases

Binary

Binary<T, U>: (this: U, value: T, index: number) => Key

Specifies which group an element in the input collection belongs to.

param

collection value

param

collection index

returns

object key

Type parameters

  • T

  • U

Type declaration

    • (this: U, value: T, index: number): Key
    • Parameters

      • this: U
      • value: T
      • index: number

      Returns Key

Indicator

Indicator<T, U>: Nullary<U> | Unary<T, U> | Binary<T, U>

Specifies which group an element in the input collection belongs to.

param

collection value

param

collection index

returns

object key

Type parameters

  • T

  • U

Key

Key: string | symbol | number

Object key.

Nullary

Nullary<U>: (this: U) => Key

Specifies which group an element in the input collection belongs to.

returns

object key

Type parameters

  • U

Type declaration

    • (this: U): Key
    • Parameters

      • this: U

      Returns Key

Unary

Unary<T, U>: (this: U, value: T) => Key

Specifies which group an element in the input collection belongs to.

param

collection value

returns

object key

Type parameters

  • T

  • U

Type declaration

    • (this: U, value: T): Key
    • Parameters

      • this: U
      • value: T

      Returns Key

Functions

Export assignment groupBy

  • Groups values according to an indicator function.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The value returned by an indicator function should be a value which can be serialized as an object key.

    • If provided an empty collection, the function returns an empty object.

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      collection to group

    • indicator: Indicator<T, U>

      indicator function specifying which group an element in the input collection belongs to

    Returns ValuesResults < T >

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var out = groupBy( arr, indicator );
    // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
  • Groups values according to an indicator function.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The value returned by an indicator function should be a value which can be serialized as an object key.

    • If provided an empty collection, the function returns an empty object.

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      collection to group

    • options: IndicesOptions<T, U>

      function options

    • indicator: Indicator<T, U>

      indicator function specifying which group an element in the input collection belongs to

    Returns IndicesResults

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var opts = {
        'returns': 'indices'
    };
    var out = groupBy( arr, opts, indicator );
    // returns { 'b': [ 0, 1, 3 ], 'f': [ 2 ] }
  • Groups values according to an indicator function.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The value returned by an indicator function should be a value which can be serialized as an object key.

    • If provided an empty collection, the function returns an empty object.

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      collection to group

    • options: ValuesOptions<T, U> | BaseOptions<T, U>

      function options

    • indicator: Indicator<T, U>

      indicator function specifying which group an element in the input collection belongs to

    Returns ValuesResults < T >

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var opts = {
        'returns': 'values'
    };
    var out = groupBy( arr, opts, indicator );
    // returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] }
  • Groups values according to an indicator function.

    Notes

    • When invoked, the indicator function is provided two arguments:

      • value: collection value
      • index: collection index
    • The value returned by an indicator function should be a value which can be serialized as an object key.

    • If provided an empty collection, the function returns an empty object.

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      collection to group

    • options: IndicesAndValuesOptions<T, U>

      function options

    • indicator: Indicator<T, U>

      indicator function specifying which group an element in the input collection belongs to

    Returns IndicesAndValuesResults < T >

    group results

    Example

    function indicator( v ) {
        return v[ 0 ];
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var opts = {
        'returns': '*'
    };
    var out = groupBy( arr, opts, indicator );
    // returns { 'b': [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], 'f': [ [ 2, 'foo' ] ] }