KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've got the following code on a Controller def db = new Sql(dataSource) def rawLines = db.rows("SELECT name FROM LINES") def lines = [] /*(db.rows returns the values as [NAME:value] */ rawLines.each { lines.add(it.name) } /*Then, use lines */ I can't keep away the impression that there is probably some way to do this in a more elegant way, something similar to a list comprehension in Python: lines = [ l.name for l in db.rows("SELECT name FROM LINES") ] Having to declare an empty list and then populate it doesn't seem the best way of doing things... Is it possible to do something like this, or Groovy doesn't allow it?
Tags (comma-separated)
Save Edits
Cancel