Skip to content

Instantly share code, notes, and snippets.

@michaelrambeau
Last active April 2, 2017 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelrambeau/961a7e4e976519e590f1e18f4f6f724a to your computer and use it in GitHub Desktop.
Save michaelrambeau/961a7e4e976519e590f1e18f4f6f724a to your computer and use it in GitHub Desktop.
To curry or not curry, that is the question

Comparing 2 implementations of the same function, with and without currying.

To be run from Ramda playground: http://ramdajs.com/repl/

const users = [ {
name: 'Larry',
meals: [{ date: new Date()}]
}]
const hasCreatedMeals = R.curry(
(count, period, user) => {
const meals = user.meals.filter(
meal => meal.date >= period.startDate && meal.date <= period.endDate
)
return meals.length >= count
}
)
const period = { startDate: new Date(), endDate: new Date() }
const getUsers = R.filter(hasCreatedMeals(1, period))
R.compose(
R.map(R.prop('name')),
getUsers
)(users)
const users = [ {
name: 'Larry',
meals: [{ date: new Date()}]
}]
const hasCreatedMeals = count => period => user => {
const meals = user.meals.filter(
meal => meal.date >= period.startDate && meal.date <= period.endDate
)
return meals.length >= count
}
const period = { startDate: new Date(), endDate: new Date() }
const getUsers = R.filter(hasCreatedMeals(1)(period))
R.compose(
R.map(R.prop('name')),
getUsers
)(users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment