list - Is there a Groovy equivalent to Ruby's #map? -
i realize there support #each
book.findall().each(){ book-> println ">>> ${book}" }
and there's support #inject
def sentence = m.inject('message: ') { s, k, v -> s += "${k == 'likes' ? 'loves' : k} $v " }
is there support #map groovy out of box (without special libraries functional java)?
def list = [1,2,3,4].map{ num-> num + 1 } assert list == [2,3,4,5]
you want collect
.
groovy:000> [1,2,3,4].collect { num -> num + 1 } ===> [2, 3, 4, 5]
i hope helps.
Comments
Post a Comment