Skip to content

Instantly share code, notes, and snippets.

@suzdalnitski
Last active September 10, 2019 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzdalnitski/c21ad38d28339bb87eee76bad650686c to your computer and use it in GitHub Desktop.
Save suzdalnitski/c21ad38d28339bb87eee76bad650686c to your computer and use it in GitHub Desktop.
import { filter, first, get } from 'lodash/fp';
const filterByType = type =>
filter( x => x.type === type );
const fruits = [
{ type: 'apple', price: 1.99 },
{ type: 'orange', price: 2.99 },
{ type: 'grape', price: 44.95 }
];
const getFruitPrice = type => fruits =>
fruits
|> filterByType(type)
|> first
|> get('price');
const getApplePrice = getFruitPrice('apple');
console.log('apple price', getApplePrice(fruits));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment