khernik
khernik

Reputation: 2091

Transform map values in Jenkins Pipeline groovy

I have a LinkedList in which I want to change all values. With the array I can do simply:

arr = arr.collect { arr -> transformFunction(arr) }

But with the LinkedList:

list = list.collect { key, val -> [(key): transformFunction(val)] }

But this doesn't work unfortunately (at least in the pipeline). What is the correct way to do this in groovy?

Upvotes: 1

Views: 1225

Answers (1)

cfrick
cfrick

Reputation: 37008

I think you mean a Map and not a List. So if you want to transform the values, then each is good for side effects:

notalist.each { k,v -> list[k] = transformFunction(v) }

Or you can create a copy with collectEntries:

newmap = map.collectEntries{ k, v -> [k, transformFunction(v)] }

Upvotes: 1

Related Questions