Last active
November 4, 2019 22:11
-
-
Save jasonknight/200a232dffc8875427d90a09d3b79906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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