Predicate<T>
Overview
The Blocks that defines a set of criteria and determines whether the specified object meets those criteria.
Use case
You can use this block to represent a method that will perform some check on the object.
For example if you need to find all item that meets some criteria in the list you can use List<T> method that takes an Predicate<T> block:
var Items := new List<String>(["John", "Jack", "Steve"]);
var Found := Items.FindAll(method (item: String): Boolean begin
exit item.StartsWith("J");
end);
Found.ForEach(item -> writeln(item));
In this example we've used an anonymous method, but it can be used with a static method or lambda expression:
var Found := Items.FindAll(item -> item.StartsWith("J"));
Location
- Reference: Sugar
- Namespace: Sugar.Collections
- Ancestry: MulticastDelegate | Predicate<T>
See Also
- Blocks
- Anonymous Methods
- Anonymous Methods