Skip to content

Instantly share code, notes, and snippets.

@stewartbryson
Forked from timyates/tap.groovy
Created August 11, 2014 16:44
Show Gist options
  • Save stewartbryson/6709908d4826f8f486fa to your computer and use it in GitHub Desktop.
Save stewartbryson/6709908d4826f8f486fa to your computer and use it in GitHub Desktop.
@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