Open
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?