Skip to content

Instantly share code, notes, and snippets.

@elventear
Forked from michalbcz/gist:2757630
Last active August 29, 2015 13:58
Show Gist options
  • Save elventear/9942740 to your computer and use it in GitHub Desktop.
Save elventear/9942740 to your computer and use it in GitHub Desktop.
emulate collectWithIndex
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment