Last active
December 20, 2015 11:49
-
-
Save timyates/6126218 to your computer and use it in GitHub Desktop.
Tap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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