documentcloud / documentcloud/underscore-contrib
Would an _.if function be useful?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 622
- Forks
- 114
- PR merge metrics
- No merged PRs in 30d
Description
_.if would take two arguments, a primary function and a conditional function. It would return a new function that, when called, will call the primary function only if the conditional (called with the same arguments) returns a truthy value. It would look something like this:
_.if = function(func, condition){
return function(){
if (condition.apply(this, arguments)){
return func.apply(this, arguments);
}
}
};
This way you can write generic functions and then easily add conditions for execution when passing them to iterators. Something like:
items.forEach(_(processItem).if(isNotProcessed));
Would this be a useful addition?
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
No file, test, or entry point is named. Start by reviewing existing function utilities and iterator-related APIs in the repository, then assess whether the proposed _.if behavior has clear acceptance criteria. Done would require a maintainer decision plus implementation and tests, none of which the issue specifies.
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
- Needs clarification
- Newbie friendliness
- 25/100