class ListOps {
static append(list1, list2) {
list1+list2
}
static concatenate(lists) {
lists.collectMany{ it }
}
static filter(list, fn) {
list.findAll fn
}
static length(list) {
list.size()
}
static map(list, fn) {
list.collect fn
}
static foldl(list, fn, initial) {
list.inject(initial, {acc, elm-> fn(acc,elm)})
}
static foldr(list, fn, initial) {
list.reverse().inject(initial, {acc, elm-> fn(acc,elm)})
}
static reverse(list) {
list.reverse()
}
}