Groovy web console

subscribe to the feed Subscribe
to this
site
Customer Accounts (via #groovywebconsole)
tweet this snippet Tweet
this
script

Customer Accounts

Published 2 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.transform.Canonical
@Canonical class Customer { List<Account> accounts }
@Canonical class Account { String number }

def getCustomers() {
    [ 
        new Customer([ new Account("1"), new Account("2")]),
        new Customer([ new Account("3"), new Account("4")])
    ]
}

println getCustomers()*.accounts*.number.flatten()
// OR even
println getCustomers().accounts.number.flatten()