UNPKG

crocks

Version:

A collection of well known Algebraic Datatypes for your utter enjoyment.

28 lines (21 loc) 782 B
/** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var curry = require('../core/curry') var isFoldable = require('../core/isFoldable') var isFunction = require('../core/isFunction') function mapReduce(mapFn, reduceFn, empty, xs) { if(!isFunction(mapFn)) { throw new TypeError('mapReduce: Unary mapping function required for first argument') } if(!isFunction(reduceFn)) { throw new TypeError('mapReduce: Binary reduction function required for second argument') } if(!isFoldable(xs)) { throw new TypeError('mapReduce: Foldable required for fourth argument') } return xs.reduce( function (acc, x) { return reduceFn(acc, mapFn(x)); }, empty ) } module.exports = curry(mapReduce)