crocks
Version:
A collection of well known Algebraic Datatypes for your utter enjoyment.
29 lines (22 loc) • 711 B
JavaScript
/** @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 isMonoid = require('../core/isMonoid')
var mconcatMap = require('../core/mconcatMap')
var identity = function (x) { return x; }
// mconcat : Monoid m => m -> ([ a ] | List a) -> m a
function mconcat(m, xs) {
if(!isMonoid(m)) {
throw new TypeError(
'mconcat: Monoid required for first argument'
)
}
if(!isFoldable(xs)) {
throw new TypeError(
'mconcat: Foldable required for second argument'
)
}
return mconcatMap(m, identity, xs)
}
module.exports = curry(mconcat)