-
-
Save yellowsnow/4587759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(take 25 (squares-of (integers))) |
This file contains hidden or 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-stream:0.5.1' ) | |
import groovy.stream.Stream | |
// Create a lazy unending stream of integers from 1 | |
def integers = Stream.from { x++ } using x:1 | |
// Create a stream of squares based on this stream of integers | |
def squares = Stream.from integers map { it * it } | |
// Create an Iterator that looks at the first 25 elements of squares | |
def first25 = squares.take( 25 ) | |
// Collect the elements | |
assert first25.collect() == [ 1, 4, 9, 16, 25, | |
36, 49, 64, 81, 100, | |
121, 144, 169, 196, 225, | |
256, 289, 324, 361, 400, | |
441, 484, 529, 576, 625 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
be groovier