documentcloud / documentcloud/underscore-contrib

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

Open
#225 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

after modules enhancement
Dominant language
JavaScript
Stars
622
Forks
114
PR merge metrics
No merged PRs in 30d

Description

@sktguha over in https://github.com/jashkenas/underscore/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked Underscore issue 2871 and the proposal for oneArg, twoArgs, and limitArgs. Compare the requested behavior with the repository's existing public utilities and determine the intended API, including whether aliases should be provided. Done means the scope and naming are agreed and the selected utility behavior is covered by the project's tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.