Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would an _.if function be useful? #215

Open
mattdiamond opened this issue Jul 3, 2016 · 1 comment
Open

Would an _.if function be useful? #215

mattdiamond opened this issue Jul 3, 2016 · 1 comment
Labels
after modules This should be postponed until after modularization (temporary label, see #220) enhancement

Comments

@mattdiamond
Copy link

mattdiamond commented Jul 3, 2016

_.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?

@jgonggrijp
Copy link
Contributor

I don't think being deemed "useful" is a hard condition for entry into Contrib, as Contrib is in part a testing ground to see whether people actually end up using a function (@joshuacc please correct me if I'm wrong).

That said: I can't predict whether people will find this useful, but the idea seems interesting in any case.

@jgonggrijp jgonggrijp added after modules This should be postponed until after modularization (temporary label, see #220) enhancement labels Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
after modules This should be postponed until after modularization (temporary label, see #220) enhancement
Projects
None yet
Development

No branches or pull requests

2 participants