functional programming - How do you uncurry/reverse curry in Javascript ES6? -


i have function have wrap function if exists or replace if doesn't. means number of arguments changes depending on circumstance.

here's mean -

list of columns:

const mycolumns = [     {name: 'my field', formatter: function(row, cell, value, coldef, data){         ... stuff value...         return value;     },     {name: 'my other field'} ] 

some have formatters , don't. here's partial solution 'wrapping' function:

return mycolumns.map(columns => {     function wrapformatting(value){         return `<span class="foobar">${value}</value>`     }     if( column.formatters ) {         column.formatters = _.flow(column.formatter, wrapformatting);     } else {         column.formatter = (row, cell, value) => value => wrapformatting;     } }) 

my naive expectation in else block formatter 'reverse curry'/uncurry 3 arguments , end looking this:

column.formatter = function(row, cell, value){     wrapformatting(value); } 

but eslint telling me value a) declared in upper scope , b) defined never used. if change 1 of them (so have (row, cell, value) => val => wrapformatting have them both 'defined never used'.

i feel i've missed trick, because can't have (row, cell, value) => value => wrapformatting(value) invoke function, , won't called when column.formatter called.

you looking for

column.formatter = (row, cell, value) => wrapformatting(value); 

not sure why thought you'd have value parameter twice , never call wrapformatting return it.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -