Created
November 20, 2020 18:56
-
-
Save cpurdy/fe439d2085ad5130d389f8973d8628fe to your computer and use it in GitHub Desktop.
"each" functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determine if any elements of the `Collection` match the provided criteria. | |
* | |
* @param match a function that evaluates elements of this collection for inclusion | |
* | |
* @return True if any element matched the specified criteria | |
* @return (conditional) the first element that matched the criteria | |
*/ | |
conditional Element any(function Boolean(Element) match = _ -> True) | |
{ | |
return iterator().untilAny(match); | |
} | |
/** | |
* Determine if all elements of the `Collection` match the provided criteria. | |
* | |
* @param match a function that evaluates an element of the `Collection` for inclusion | |
* | |
* @return True if every single element in the `Collection` matched the specified criteria | |
*/ | |
Boolean all(function Boolean(Element) match) | |
{ | |
return iterator().whileEach(match); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment