Find
Returns the first member of the given list that satisfies the given function, or returns null if none of the members satisfy the given function.
object Find(object[] list, bool function(object member, ...) selector, ...)
How to use it
a) One line format:
int firstNumberOverTwo = Find(intArray, function(int x){return x>2;});
b Multi-line format
function findFirst(int number) { return number > 2; } int foundValue = Find(list, findFirst);
Examples
A) Find the first item in the list that is greater than two
int list = {0, 1, 2, 3, 4}; int value = Find(list, function(int x){return x>2;}); // value = 3
B) Finds the first Point in the list that is closer than a certain distance from another selectorPoint. The selectorPoint and the distance are passed in as extra arguments.
Double distance = 3.0; Point[] pointList = {point01, point02, point03, point04}; function findFirst(Point pt, Point selectionPt, double dist) { return Distance(pt, selectionPt) < dist; } int foundValue = Find(pointList, findFirst, selectorPoint, distance);