1.1.2 • Published 9 years ago

js-mapcat v1.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

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);
});
1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago