Open
Description
@sktguha over in jashkenas/underscore#2871:
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]
When implementing this, we may want to alias _.oneArg
to _.unary
and _.limitArgs
to _.ary
in order to not create more distance from Lodash than necessary.