Echo JS 0.11.0

<~>
appz 3863 days ago. link parent 2 points
_(users).where({name: 'foo', pets: []}); // => function

Replies

CrossEye 3863 days ago. link 2 points
This gives you a 'chained' object version of the output, on which you can then run additional functions.  This can be useful in its own right, but is nothing like what buzzdecafe was suggesting in the Ramda example.

Notice that this

    R.filter(R.where({name: 'Buzz', errors: R.isEmpty}));

doesn't mention the `users` list at all.  There's a good reason; it hasn't been applied yet.  The expression above returns a function that is still waiting for you supply the list of users.  So you might assign this function to a variable or pass it to a callback, or in some other way defer executing it until you have that list:

    var buzzList = R.filter(R.where({name: 'Buzz', errors: R.isEmpty}));
    // ...
    var buzzesInAllForums = map(function(forum) {
        return buzzList(forum.users);
    }, listOfForums);

Note that the `users` parameter is not supplied until inside the callback function.  That's in good part what Ramda is about, giving you the ability to compose simple functions that can be combined later.

Of course those last three lines are not how you'd actually do this in Ramda either.  This would accomplish the same thing with less ceremony:

    var buzzesInAllForums = map(pipe(prop('users'), buzzList), listOfForums);

And again, if you wanted this to be a simple function, you could simply leave off `listOfForums`, and you'd get back a function that expects that one parameter.  That's what we think of as the beauty of Ramda.