javascript - point free where arguments are in the wrong order -


i want write function using ramda's standard function set given dictionary , key, increment value key. example

fn('foo', {}) // => {foo: 1} fn('foo', {foo: 1}) // => {foo: 2} 

i've gotten pretty close missing way curry properly.

i have method takes key , object , returns 1 more:

// count :: -> number var count = r.compose(r.inc, r.defaultto(0))  // countprop :: string -> object -> number var countprop = r.curry(r.compose(count, (r.prop(r.__))))  countprop('foo', {foo:1}) // 2 countprop('foo', {}) // 1 

now want return new data structure

// accum :: string -> object -> object var accum = r.curry(function(key, obj){   return r.assoc(key, countprop(key, obj), obj) })  accum('foo', {foo: 1}) // => {foo: 2} 

but issue in order make point free, have figure out how values in functions setup curried in proper order. doing wrong? should set function differently? tried set both dependent functions both take key first, object, i'm missing something. should considering specific functor this?

thanks!

you use r.lens:

const foolens = r.lens(r.prop('foo'), r.assoc('foo'));  foolens.map(r.inc, {foo: 1, bar: 2});  // => {foo: 2, bar: 2} foolens.map(r.inc, {foo: 2, bar: 2});  // => {foo: 3, bar: 2} foolens.map(r.inc, {foo: 3, bar: 2});  // => {foo: 4, bar: 2} 

lenses make possible create succession of values without undermining integrity of succeeded value mutating it.


Popular posts from this blog