Mahbub Rahman Mahbub Rahman - 1 month ago 4x
Groovy Question

Groovy: Iterating a list

I was trying to iterate a list and after googling, I found one solution like below:

value([0,1,2,3,4,5,6].sort{new Random()}?.take(1)[0])

I did not understand this part:
sort{new Random()}

Can someone explain this?
And which class the take method is belonging to?


sort receives a closure to determine the order that you wish. In this example, it makes a random sort.

take comes from Iterable and returns the first n elements.