Created
May 20, 2015 18:17
-
-
Save rhzs/c1cfa8c6f6fa6a7f068d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[].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