js-mapcat

1.1.2 • Public • Published

js-mapcat

Map over collections and return one level deep flattened collection

Installation

$ npm i js-mapcat

Usage

import mapcat from 'js-mapcat';
 
mapcat((x) => x * x, [1, 2]); // [1, 4]
mapcat(([x, y, z]) => x * y * z, [1, 2], [3, 4], [5, 6]); // [15, 48]
mapcat(([{a}, {b}]) => a * b, [{ a: 1 }, { a: 2 }], [{ b: 3 }, { b: 4 }]); // [3, 8]

Better example

mapcat with a single collection

Fetch multiple news feeds and produce an array of authors for every article in each feed.

Promise.all([
  fetch('feed/1'),
  fetch('feed/2'),
  fetch('feed/3')
])
.then((feeds) => {
 
  return mapcat((feed) => {
 
    return feed.map(({ author }) => author);
  }, feeds);
});

Readme

Keywords

Package Sidebar

Install

npm i js-mapcat

Weekly Downloads

17

Version

1.1.2

License

MIT

Last publish

Collaborators

  • roman01la