Guest User

Untitled

a guest
Jun 14th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def words = ['Groovy', 'Rocks', 'Big', 'Time']
  2.  
  3. def result = words.collectEntries {
  4. [(it): it.contains('o')]
  5. }
  6.  
  7. assert result.Groovy && result.Rocks
  8. assert !result.Big && !result.Time
  9.  
  10. //invert map
  11. inverted_map = map.collectEntries { k,v -> [(v):k] }
  12.  
  13. // another weird semi-related datastructure manipulation
  14. import groovy.json.*
  15.  
  16. def map = ["Server":"ABC", "Database":"sa"]
  17.  
  18. def list = map.inject([]) { result, k, v ->
  19. result << ['key': k, 'value': v]
  20. result
  21. }
  22.  
  23. println new JsonBuilder(list).toString()
Add Comment
Please, Sign In to add comment