Skip to content

Instantly share code, notes, and snippets.

@jasonknight
Last active November 4, 2019 22:11
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 jasonknight/200a232dffc8875427d90a09d3b79906 to your computer and use it in GitHub Desktop.
Save jasonknight/200a232dffc8875427d90a09d3b79906 to your computer and use it in GitHub Desktop.
var users = [
{
role: 'admin',
email: 'fakeadmin1@email.com'
},
{
role: 'user',
email: 'fake2@email.com'
},
{
role: 'admin',
email: 'fakeadmin2@email.com'
},
];
function compose(f,g) {
return function (x) {
return f(g(x));
};
}
function property(p) {
return function (x) {
return x[p];
};
}
function propertyp(v) {
return function (p) {
return function (o) {
return property(p)(o) == v;
};
};
}
function map(fn) {
return function (list) {
return list.map(fn);
};
}
function filter(fn) {
return function(list) {
return list.filter(fn);
}
}
function onlyAdmins() {
return filter(propertyp('admin')('role'));
}
function onlyEmails() {
return map(property('email'));
}
var getAdminEmails = compose(
onlyEmails(),
onlyAdmins());
var admin_emails = getAdminEmails(users);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment