Comparing 2 implementations of the same function, with and without currying.
To be run from Ramda playground: http://ramdajs.com/repl/
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) |