I have this bit of code:
var fn = function(fn, name) {
this.commands.add(name, fn);
}.bind(this);
_.mapObjIndexed(fn, this.commandList);
I feel like there's a way to improve this bit of code and make it just one line. I tried many different ways, but I'm new to ramda.js
and I might be missing some function, that would make this easier and simpler.
You seem to be looking for the flip
function / flip
function :
_.mapObjIndexed(_.flip(this.commands.add), this.commandList);
If a .bind(this.commands)
for the add
function is necessary, you can shorten that using _.bindKey (this.commands, "add")
.
If the flipping doesn't work correctly because of the number of arguments, you might needt to throw in _.ary(…, 2)
or _.binary(…)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.