Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def words = ['Groovy', 'Rocks', 'Big', 'Time']
- def result = words.collectEntries {
- [(it): it.contains('o')]
- }
- assert result.Groovy && result.Rocks
- assert !result.Big && !result.Time
- //invert map
- inverted_map = map.collectEntries { k,v -> [(v):k] }
- // another weird semi-related datastructure manipulation
- import groovy.json.*
- def map = ["Server":"ABC", "Database":"sa"]
- def list = map.inject([]) { result, k, v ->
- result << ['key': k, 'value': v]
- result
- }
- println new JsonBuilder(list).toString()
Add Comment
Please, Sign In to add comment