Groovy web console

subscribe to the feed Subscribe
to this
site

TestBRR

Published 1 month ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts

class User {    String name
    String city
    Date birthDate
    public String toString() { "$name" }}
def me = new User(name:'mrhaki', city:'Tilburg', birthDate:new Date(73,9,7))
def users = [
    me,
    me,
    new User(name:'mrhaki', city:'Tilburg', birthDate:new Date(73,9,7)),
    new User(name:'mrhaki', city:'Tilburg', birthDate:new Date(73,9,7)),
    new User(name:'bob', city:'New York', birthDate:new Date(63,3,30)),
    new User(name:'britt', city:'Amsterdam', birthDate:new Date(80,5,12)),
    new User(name:'kim', city:'Amsterdam', birthDate:new Date(83,3,30)),
    new User(name:'liam', city:'Tilburg', birthDate:new Date(109,3,6))
]// Helper closure for asserts.
def userToString = { it.toString() }// Group by city property of user object:
def usersByCity = users.groupBy({ user -> user })
println(usersByCity)