Skip to content

Would an _.if function be useful? #215

Description

@mattdiamond

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    after modulesThis should be postponed until after modularization (temporary label, see #220)enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions