Package Exports
- array-mapcat
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-mapcat) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
array-mapcat
Curried function deriving new array values by applying provided function to each item/index of provided array then applying
concat
to the results. Fast and compatible with modern or old browsers.
npm install array-mapcat --save
You can also use Duo, Bower or download the files manually.
npm stats
Overview
- Similar to
[].concat.apply([], [].map())
but more functional and compositionally friendly. - Optionally, a dot-notation formatted string may be provided for item property access.
API Example
Basic
var mapcat = require('array-mapcat')
var splitword = (sentance) => sentance.split(/\s+/)
var sentences = [ 'two birds', 'three green peas' ]
mapcat(splitword, sentences)
//=> ['two', 'birds', 'three', 'green', 'peas']
Dot-notation object access
var mapcat = require('array-mapcat')
var listmodel = [
{ list: [1, 2, 3] },
{ list: [4, 5, 6] },
{ list: [7, 8, 9] }
]
mapcat('list', listmodel)
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Pointfree Style
var mapcat = require('array-mapcat')
var listmodel = Promise.resolve([
{ list: [1, 2, 3] },
{ list: [4, 5, 6] },
{ list: [7, 8, 9] }
])
listmodel.then(mapcat('list'))
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
API
mapcat(fn, list)
arguments
fn (Function|String)
Function to apply to each item.list (array)
Array to iterate over.
returns
(array)
Array resulting from applying provided functionfn
to each item oflist
then applyingconcat
to the results.
Inspiration
Alternatives
Contributing
SEE: contributing.md