Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Groovy Higher order functions
class Person {
String name
int age
Gender gender
enum Gender {
MALE, FEMALE, UNKNOWN
}
}
def persons = [new Person(name: 'Bob', age: 25, gender: Person.Gender.MALE),
new Person(name: 'Alice', age: 42, gender: Person.Gender.FEMALE)]
persons.findAll {
Person v ->
(v.age < 27 &&
v.age > 24 &&
(v.gender == Person.Gender.MALE || v.gender ==Person.Gender.UNKNOWN))
}.collect{ "${it.name}, ${it.age}, ${it.gender}" }
@O5ten

This comment has been minimized.

Copy link
Owner Author

O5ten commented May 8, 2015

Output:
[Bob, 25, MALE]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.