anru / sprout

A set of functions to work with nested data
BSD 3-Clause "New" or "Revised" License
56 stars 10 forks source link

Better composability #4

Open jstcki opened 10 years ago

jstcki commented 10 years ago

It would be nice if there were alternative Sprout functions which took the object as the last argument or even better created partially applied functions.

They could be named with the suffix 'With', similar like in allong.es.

For example:

var getName = sprout.getWith('name');
getName({name: 'foo'}); // => 'foo'
getName({name: 'bar'}); // => 'bar'
someArray.map(getName);
anru commented 5 years ago

Partial application should solve this issue in a language level, I think.

Also, probably better way is add examples how users could use currying to existing sprout methods. Like this:

const { curryRight } = require('robust-and-already-exists-curry-library')

const getName = curryRight(sprout.get, 'name')

getName({name: 'foo'}) // => 'foo'
getName({name: 'bar'}) // => 'bar'
someArray.map(getName)