Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Interfaces

Type aliases

Functions

Type aliases

Binary

Binary: (value: any, 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 declaration

    • (value: any, index: number): boolean
    • Parameters

      • value: any
      • index: number

      Returns boolean

Nullary

Nullary: () => 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 declaration

    • (): boolean
    • Returns boolean

Predicate

Predicate: Nullary | Unary | Binary

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

Unary

Unary: (value: any) => 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 declaration

    • (value: any): boolean
    • Parameters

      • value: any

      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.

    Parameters

    • collection: Collection

      input collection

    • predicate: Predicate

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

    Returns Array < Array < any > >

    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.

    Parameters

    • collection: Collection

      input collection

    • options: Options

      function options

    • predicate: Predicate

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

    Returns Array < Array < any > >

    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 ] ]

    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' ] ] ]