diff --git a/src/as/com/threerings/util/ArrayUtil.as b/src/as/com/threerings/util/ArrayUtil.as index 8499431d4..5f40bd09d 100644 --- a/src/as/com/threerings/util/ArrayUtil.as +++ b/src/as/com/threerings/util/ArrayUtil.as @@ -118,6 +118,19 @@ public class ArrayUtil return -1; // never found } + /** + * Returns the first item in the array for which the predicate function returns true, or + * -1 if no such item was found. The predicate function should be of type: + * function (element :*) :Boolean { } + * + * @return the matching element, or null if no matching element was found + */ + public static function findIf (arr :Array, predicate :Function) :* + { + var index :int = (arr != null ? indexIf(arr, predicate) : -1); + return (index >= 0 ? arr[index] : null); + } + /** * Returns the first index of the supplied element in the array. Note that if the element * implements Equalable, an element that is equals() will have its index returned, instead