Home Reference Source Test Repository

lib/concatMap.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.concatMap = concatMap;
/**
 * Map a function over the concatenation of all the elements of a list.
 *
 * @since v0.1.0
 * @param {Function} fn - The function to be mapped
 * @param {Array} list - The list to concatenate
 * @return {Array}
 * @example
 *   concatMap(a => a * 2, [[4, 5, 6], [1, 2, 3]]) // => [8, 10, 12, 2, 4, 6]
 */
function concatMap(fn, list) {
  return list.reduce(function (a, b) {
    return a.concat(b);
  }).map(function (l) {
    return fn(l);
  });
}