Skip to content

Instantly share code, notes, and snippets.

@timyates
Created June 28, 2012 10:58
Show Gist options
  • Select an option

  • Save timyates/3010668 to your computer and use it in GitHub Desktop.

Select an option

Save timyates/3010668 to your computer and use it in GitHub Desktop.
takeWhile/dropWhile in groovy 2.0
def str = 'Groovy is cool'
assert str.takeWhile { it != ' ' } == 'Groovy'
assert str.dropWhile { it != ' ' } == ' is cool'
def a = 1..10
assert a.takeWhile { it < 5 } == [ 1, 2, 3, 4 ]
assert a.dropWhile { it < 5 } == [ 5, 6, 7, 8, 9, 10 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment