Skip to content

Instantly share code, notes, and snippets.

@goloroden
Created December 16, 2011 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goloroden/1485958 to your computer and use it in GitHub Desktop.
Save goloroden/1485958 to your computer and use it in GitHub Desktop.
Combining Funcs
Func<User, bool> whereStatus = u => u.Status == status;
Func<User, bool> whereQuery =
u => u.Lastname.Contains(q) || u.Firstname.Contains(q) || u.UserId.Contains(q);
Func<User, bool> where = ...?
// What's requires: where = whereStatus && whereQuery
@forki
Copy link

forki commented Dec 16, 2011

Try to implement public static Func<T, bool> And (this Func<T, bool> a, Func<T, bool>)

@goloroden
Copy link
Author

http://stackoverflow.com/a/491850 worked for me :-)

The term "predicate" was the missing link.

@forki
Copy link

forki commented Dec 16, 2011

Mhm I shouldn't have used generic parameters in a comment. They are all lost.

@forki
Copy link

forki commented Dec 16, 2011

Jon's solution is nice. Nevertheless tee implementation for my solution (you need to add the type parameters for the funcs) : return x => a(x) && b(x) ;

@forki
Copy link

forki commented Dec 18, 2011 via email

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