Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

Binary

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

Returns a boolean indicating which group an element in an collection belongs to.

param

collection value

param

collection index

returns

boolean indicating whether an element in a collection should be placed in the first or second group

Type parameters

  • T

  • U

Type declaration

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

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

      Returns boolean

Nullary

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

Returns a boolean indicating which group an element in an collection belongs to.

returns

boolean indicating whether an element in a collection should be placed in the first or second group

Type parameters

  • U

Type declaration

    • (this: U): boolean
    • Parameters

      • this: U

      Returns boolean

Predicate

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

Returns a boolean indicating which group an element in an collection belongs to.

param

collection value

param

collection index

returns

boolean indicating whether an element in a collection should be placed in the first or second group

Type parameters

  • T

  • U

Unary

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

Returns a boolean indicating which group an element in an collection belongs to.

param

collection value

returns

boolean indicating whether an element in a collection should be placed in the first or second group

Type parameters

  • T

  • U

Type declaration

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

      • this: U
      • value: T

      Returns boolean

Functions

Export assignment bifurcateBy

  • Splits values into two groups according to a predicate function.

    Notes

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

      • value: collection value
      • index: collection index
    • If a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.

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

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      input collection

    • predicate: Predicate<T, U>

      predicate function indicating which group an element in the input collection belongs to

    Returns [ ]

    group results

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var out = bifurcateBy( arr, predicate );
    // returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
  • Splits values into two groups according to a predicate function.

    Notes

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

      • value: collection value
      • index: collection index
    • If a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.

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

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      input collection

    • options: IndicesOptions<T, U>

      function options

    • predicate: Predicate<T, U>

      predicate function indicating which group an element in the input collection belongs to

    Returns [ ]

    group results

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var opts = {
        'returns': 'indices'
    };
    var out = bifurcateBy( arr, opts, predicate );
    // returns [ [ 0, 1, 3 ], [ 2 ] ]
  • Splits values into two groups according to a predicate function.

    Notes

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

      • value: collection value
      • index: collection index
    • If a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.

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

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      input collection

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

      function options

    • predicate: Predicate<T, U>

      predicate function indicating which group an element in the input collection belongs to

    Returns [ ]

    group results

    Example

    function predicate( v ) {
        return v[ 0 ] === 'b';
    }
    var arr = [ 'beep', 'boop', 'foo', 'bar' ];
    
    var opts = {
        'returns': 'values'
    };
    var out = bifurcateBy( arr, opts, predicate );
    // returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
  • Splits values into two groups according to a predicate function.

    Notes

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

      • value: collection value
      • index: collection index
    • If a predicate function returns a truthy value, a collection value is placed in the first group; otherwise, a collection value is placed in the second group.

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

    Type parameters

    • T

    • U

    Parameters

    • collection: Collection<T>

      input collection

    • options: IndicesAndValuesOptions<T, U>

      function options

    • predicate: Predicate<T, U>

      predicate function indicating which group an element in the input collection belongs to

    Returns [ ]

    group results

    Example

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