集合的 Groovy 映射方法

在 Groovy 中有 map方法吗? 我想做一些类似于我对以下 Scala 代码片段所做的事情:

scala> val l = List(1, 2, 3)
l: List[Int] = List(1, 2, 3)


scala> l.map(_ + 1)
res0: List[Int] = List(2, 3, 4)
55295 次浏览

There is such a method in groovy, it is called collect, for example:

assert [1, 2, 3].collect { it * 2 } == [2, 4, 6]

http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#_iterating_on_a_list