I've seen time and time again API (particularly in the .NET framework) that uses Func<TObject, bool>
when Predicate<TObject>
is seemingly a perfectly responsible option. What good reasons might an API designer have for doing so?
In LINQ, Func<T, bool>
is used for things like Where
so that the other overload which takes the index as well as the element is consistent:
IEnumerable<T> Where(IEnumerable<T> source, Func<T, bool> predicate)
IEnumerable<T> Where(IEnumerable<T> source, Func<T, int, bool> predicate)
Personally I think the name Predicate
is more descriptive, so I would use it in situations where there's no consistency issue like the one above. Mind you, there's something to be said for only needing to know about the Action
and Func
delegate types...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With