documentcloud / documentcloud/underscore-contrib
Add _.withDefault combinator
Open
@joshuacc is already working on this.
Since Jul 31, 2014.
after modules
enhancement
- Dominant language
- JavaScript
- Stars
- 622
- Forks
- 114
- PR merge metrics
- No merged PRs in 30d
Description
The _.withDefault function would accept a function as its argument, and returns a new function that transparently replaces null/undefined return values with a default value.
Example:
function getArrLength (arr) {
if (_.isArray(arr)) return arr.length;
}
getArrLengthOrZero = _.withDefault(getArrLength, 0);
getArrLengthOrZero({});
// => 0
May need a better name for the function, though.
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.
Assessment
This issue has not been assessed yet.