Skip to content

Instantly share code, notes, and snippets.

@stefanfrede
Created August 22, 2016 05:23
Show Gist options
  • Select an option

  • Save stefanfrede/c85b6885ead63c5c56ddaacaad0be06a to your computer and use it in GitHub Desktop.

Select an option

Save stefanfrede/c85b6885ead63c5c56ddaacaad0be06a to your computer and use it in GitHub Desktop.
Combine the mapWith and the getWith recipe.
const pluckWith = (attr) => mapWith(getWith(attr));
// or even better
const pluckWith = compose(mapWith, getWith);
/**
* Example
*/
const inventories = [
{ apples: 0, oranges: 144, eggs: 36 },
{ apples: 240, oranges: 54, eggs: 12 },
{ apples: 24, oranges: 12, eggs: 42 }
];
pluckWith('eggs')(inventories)
//=> [ 36, 12, 42 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment