Skip to content

Suggestion: _.oneArg, possibly _.twoArgs and/or _.limitArgs #225

Open
@jgonggrijp

Description

@jgonggrijp

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    after modulesThis should be postponed until after modularization (temporary label, see #220)enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions