Skip to content

Instantly share code, notes, and snippets.

View frankscholten's full-sized avatar

Frank Scholten frankscholten

View GitHub Profile
@michalbcz
michalbcz / gist:2757630
Created May 20, 2012 10:47
groovy - when you're missing collectWithIndex method...
List.metaClass.collectWithIndex = { yield ->
def collected = []
delegate.eachWithIndex { listItem, index ->
collected << yield(listItem, index)
}
return collected
}
assert [1, 1, 1, 1, 1].collectWithIndex { it, index -> it + index } == [1, 2, 3, 4, 5]