2.1.1 • Published 8 years ago

@f/reduce-filter v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

reduce-filter

Build status Git tag NPM version Code style

Generates a reducer that filters its accumulator by reducing each of its items to a boolean value. That is somewhat complicated to state, but easy to read as code:

function reduceFilter (fn) {
  return function (state, value) {
    return filter(predicate, state)

    function predicate (item, key) {
      return fn(item, value, key)
    }
  }
}

Installation

$ npm install @f/reduce-filter

Usage

var reduceFilter = require('@f/reduce-filter')

reduceFilter(isDivisbleBy)([1, 2, 3, 4, 5], 2) // -> [2, 4]

function isDivisbleBy (m, n) {
  return m % n === 0
}

API

reduceFilter(fn)

  • fn - Accepts (item, value, key) and returns a bool, indicating whether or not to retain item.

Returns: Returns a reducing function that accepts (state, value) and returns a new container of type state filtered by fn.

License

MIT