Skip to content

Instantly share code, notes, and snippets.

@timyates
Last active December 20, 2015 11:49
Show Gist options
  • Save timyates/6126218 to your computer and use it in GitHub Desktop.
Save timyates/6126218 to your computer and use it in GitHub Desktop.
Tap
@Grab( 'com.bloidonia:groovy-common-extensions:0.5' )
def m = (1..10) .tap { println "original ${it}" }
.findAll { it % 2 == 0 } .tap { println "evens ${it}" }
.collect { it * it } .tap { println "squares ${it}" }
// prints:
// original [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// evens [2, 4, 6, 8, 10]
// squares [4, 16, 36, 64, 100]
// and returns:
assert m == [4, 16, 36, 64, 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment