Skip to content

Instantly share code, notes, and snippets.

@rhzs
Created May 20, 2015 18:17
Show Gist options
  • Save rhzs/c1cfa8c6f6fa6a7f068d to your computer and use it in GitHub Desktop.
Save rhzs/c1cfa8c6f6fa6a7f068d to your computer and use it in GitHub Desktop.
[].eachWithPeek { current, peek ->
assert false // shouldn't get here, nothing to iterate through
}
[1].eachWithPeek { current, peek ->
assert current == 1
assert peek == null // only 1 element, nothing to peek at
}
def results = []
[1, 2, 3, 4, 5].eachWithPeek { current, peek ->
results << [current, peek]
}
assert results == [[1, 2], [2, 3], [3, 4], [4, 5], [5, null]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment