Skip to content

Add a counter-like predicate #24

Open
@lazdmx

Description

@lazdmx

I suggest to add some general counting functions into lib, which is useful with methods like partitionBy, #map, ...

function plus_if( fn, init ){
  var v = init || 0;
  return function( ){
    return v += fn.apply( null, arguments );
  }
}

It can be use like this:

var barriers = [ 1, 0, 0, 1, 0, 1, 1, 0, 0, 0 ];
sections = _.partitionBy( barriers, plus_if( _.identity ) );


// => [ [ 1, 0, 0 ], [ 1, 0 ], [ 1 ], [ 1, 0, 0, 0 ] ]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions