bingo-functional-js
Version:
A port of the PHP bingo-functional library
20 lines (17 loc) • 414 B
JavaScript
const fold = require('./fold')
const reverse = require('./reverse')
/**
* foldRight function
*
* foldRight :: (a -> b -> a) -> [b] -> a -> a
* @param {function} func
* @param {(array|object)} list
* @param {*} acc
* @returns {*}
* @example
*
* foldRight((acc, val) => acc + val, [1, 2], 0)
* // => 3
*/
const foldRight = (func, list, acc) => fold(func, reverse(list), acc)
module.exports = foldRight