Skip to content

Instantly share code, notes, and snippets.

@cpurdy
Created November 20, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpurdy/fe439d2085ad5130d389f8973d8628fe to your computer and use it in GitHub Desktop.
Save cpurdy/fe439d2085ad5130d389f8973d8628fe to your computer and use it in GitHub Desktop.
"each" functionality
/**
* 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