The take and drop methods were added to the list object in groovy v 1.8.1, and work like this:
def list = ['Simple', 'list', 'with', 5, 'items']
assert list.take(2) == ['Simple', 'list']
I only have v 1.8.0 available to me. How can I reimplement my own version of list.take(2) using Groovy v1.8.0 ?
Is it possible to do something like:
def list = ['Simple', 'list', 'with', 5, 'items']
def limit = 2
assert list['0..'+limit] == ['Simple', 'list']
When I try this I get an exception.
Slicing might accomplish the same goal: