Skip to content

Instantly share code, notes, and snippets.

@jasonknight
Last active November 4, 2019 22:11
Show Gist options
  • Select an option

  • Save jasonknight/200a232dffc8875427d90a09d3b79906 to your computer and use it in GitHub Desktop.

Select an option

Save jasonknight/200a232dffc8875427d90a09d3b79906 to your computer and use it in GitHub Desktop.

Revisions

  1. jasonknight revised this gist Nov 4, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions FPWay.js
    Original file line number Diff line number Diff line change
    @@ -39,13 +39,13 @@ function filter(fn) {
    return list.filter(fn);
    }
    }
    function onlyadmins() {
    function onlyAdmins() {
    return filter(propertyp('admin')('role'));
    }
    function onlyemails() {
    function onlyEmails() {
    return map(property('email'));
    }
    var getAdminEmails = compose(
    onlyemails(),
    onlyadmins());
    onlyEmails(),
    onlyAdmins());
    var admin_emails = getAdminEmails(users);
  2. jasonknight revised this gist Nov 4, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions FPWay.js
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,10 @@ function filter(fn) {
    function onlyadmins() {
    return filter(propertyp('admin')('role'));
    }
    function onlyemails() {
    return map(property('email'));
    }
    var getAdminEmails = compose(
    map(property('email')),
    filter(propertyp('admin')('role')));
    onlyemails(),
    onlyadmins());
    var admin_emails = getAdminEmails(users);
  3. jasonknight created this gist Nov 4, 2019.
    48 changes: 48 additions & 0 deletions FPWay.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    var users = [
    {
    role: 'admin',
    email: '[email protected]'
    },
    {
    role: 'user',
    email: '[email protected]'
    },
    {
    role: 'admin',
    email: '[email protected]'
    },
    ];
    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'));
    }
    var getAdminEmails = compose(
    map(property('email')),
    filter(propertyp('admin')('role')));
    var admin_emails = getAdminEmails(users);