You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest adding a new function called oneArg to underscore. It wraps a function and allows it to be called with one argument only and ignores rest of the arguments.
Implementation: const oneArg = fn => arg => fn(arg);
Thanks for the suggestion, @sktguha! It is an interesting idea. I'm cross-posting this to our companion project, Underscore-contrib, because I think it should be added there first before we consider making it part of the core library.
In the meanwhile, your particular use case can also be handled using _.partial:
I suggest adding a new function called oneArg to underscore. It wraps a function and allows it to be called with one argument only and ignores rest of the arguments.
Implementation:
const oneArg = fn => arg => fn(arg);
usage:
Before oneArg:
['34','11','19','199','201'].map(parseInt); // returns [34, NaN, 1, 1, 33]
After oneArg:
const safeParseInt = oneArg(parseInt); ['34','11','19','199','201'].map(safeParseInt) // returns [34, 11, 19, 199, 201]
The text was updated successfully, but these errors were encountered: