Groovy web console

subscribe to the feed Subscribe
to this
site
embed in your blog Embed
this
script
Inject with map and spreading (via #groovywebconsole)
tweet this snippet Tweet
this
script

To embed this script in your site, just drop the content below where you want to embed it.

Inject with map and spreading

Published 1 month ago by glaforge with tags inject map spread operator
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def x = [1,2,3].inject([:]) { map, it ->
    [*:map, (it): it <= 2 ? 'safe' : 'charm']
}

assert x == [1: 'safe', 2: 'safe', 3: 'charm']

Recent scripts