Last active
November 10, 2017 22:32
-
-
Save O5ten/7215b56d57316044f0ac to your computer and use it in GitHub Desktop.
Groovy Higher order functions
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
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}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
[Bob, 25, MALE]