Is there a map
method in Groovy? I want to do something like I do with the following Scala snippet:
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)
If you wanted to do it that way, iterate over map. keySet() and the rest will work as you expected. It should work if you use s. key & s.
2. The each Method. In Groovy, maps created with the literal notation are ordered.
Groovy - collect()The method collect iterates through a collection, converting each element into a new value using the closure as the transformer.
Groovy - Lists contains() Returns true if this List contains the specified value.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With