UNPKG

crocks

Version:

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

26 lines (20 loc) 629 B
/** @license ISC License (c) copyright 2016 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ var curry = require('../core/curry') var isFoldable = require('../core/isFoldable') var isFunction = require('../core/isFunction') var fl = require('../core/flNames') function reduce(fn, init, m) { if(!isFunction(fn)) { throw new TypeError( 'reduce: Function required for first argument' ) } if(!isFoldable(m)) { throw new TypeError( 'reduce: Foldable required for third argument' ) } return (m[fl.reduce] || m.reduce).call(m, fn, init) } module.exports = curry(reduce)