KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
If I have a Set that I know contains a single element, what's the best way to extract it? The best I can come up with is this, but it doesn't feel very groovy: set = [1] as Set e = set.toList()[0] assert e == 1 If I'm dealing with a list, I've got lots of nice ways to get the element, none of which seem to work with Sets: def list = [1] e = list[0] (e) = list e = list.head()
Tags (comma-separated)
Save Edits
Cancel