Created
April 29, 2020 00:40
-
-
Save bdkosher/14c81a2ac80a7ae29985cd66066b1ba1 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
/*def imewi = Iterable.metaClass.eachWithIndex | |
def lmewi = List.metaClass.eachWithIndex | |
println imewi | |
println lmewi | |
def iewi = Iterable.&eachWithIndex | |
def lewi = List.&eachWithIndex | |
*/ | |
def eachWithLast = { Closure c -> | |
int size = delegate.size() | |
delegate.eachWithIndex { item, idx -> | |
boolean last = idx == size - 1 | |
c(item, last) | |
} | |
} | |
def cewl = { item, last -> | |
println "$item is ${last ? '' : 'not '}last" | |
} | |
List.metaClass.eachWithLast << eachWithLast | |
[1, 2, 3].eachWithLast cewl | |
['a','b','c'].eachWithLast cewl | |
Iterable.metaClass.eachWithLast << eachWithLast | |
import java.nio.file.* | |
Path path = FileSystems.getDefault().getPath(/C:\Users\jwolf2\Desktop/); | |
path.eachWithLast { item, last -> | |
println "$item is ${last ? '' : 'not '}last" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment