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 fromIterable
and returns the first n elements.