Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Last active November 18, 2018 21:04
Show Gist options
  • Save miladvafaeifard/f6ba9cba80cd8cd1f108a69be1bb35a1 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/f6ba9cba80cd8cd1f108a69be1bb35a1 to your computer and use it in GitHub Desktop.
Ramda.js is a great library to aid in creating functional code as it has some great built-in methods.
const data = [
{ from: 'Holman Serrano', priority: 'normal', subject: 'Payment due' },
{ from: 'Holman Serrano', priority: 'high', subject: 'Payment due' },
{ from: 'Barbra Rasmussen', priority: 'low', subject: 'Payment due' },
{ from: 'Anastasia Cherry', priority: 'high', subject: 'Payment due' },
{ from: 'Holman Serrano', priority: 'high', subject: 'Weekend BBQ' },
{ from: 'Baird Montoya', priority: 'low', subject: 'Weekend BBQ' },
{ from: 'Flores Aguilar', priority: 'low', subject: 'Payment due' }
];
const fakeApi = function() {
return new Promise((resolve, reject) => {
resolve(data);
});
};
import * as R from 'ramda';
const getPaymentReminders = function(priority, subject) {
return fakeApi()
.then(R.filter(R.propEq('priority', priority)))
.then(R.filter(R.where({ subject: R.contains(subject)})))
.then(R.sortBy(R.prop('from')));
}
getPaymentReminders('normal', 'Payment')
.then(list => console.log(list))
.catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment