documentcloud / documentcloud/underscore-contrib
Suggestion: _.oneArg, possibly _.twoArgs and/or _.limitArgs
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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