在Grails中的each()中的最后一项上运行命令

Jas*_*ean 2 each grails groovy

我有一系列"任务",我从我正在迭代的JSON响应中获取,并对每个任务进行一些处理.这是一些psudocode:

def tasks = grails.converters.JSON.parse(json response)
tasks.each() {task ->
  //do some processing here
}
Run Code Online (Sandbox Code Playgroud)

在列表中的最后一个任务中,我想运行一个额外的操作.我正在寻找一种内置的方式来实现grails/groovy.到目前为止,我的搜索没有结果.

Ale*_*uch 7

另一种可能的解决方案

tasks.eachWithIndex() { task, i ->
//whatever
   if(i == tasks.size() - 1){
      //something else
   }
}
Run Code Online (Sandbox Code Playgroud)