sprout icon indicating copy to clipboard operation
sprout copied to clipboard

Better composability

Open jstcki opened this issue 10 years ago • 1 comments

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);

jstcki avatar Jun 22 '14 19:06 jstcki

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)

anru avatar Jun 22 '19 06:06 anru