daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top