Slide 169
Slide 169 text
Groovy-stream library
!64
@Grab(
'com.bloidonia:groovy-‐stream:0.5.2'
)
import
groovy.stream.Stream
!
def
integers
=
Stream.from
{
x++
}
using
x:
1
def
squares
=
Stream.from
integers
map
{
it
*
it
}
def
first5
=
squares.take(
5
).collect()
!
assert
first5
==
[
1,
4,
9,
16,
25
]
!
def
s
=
Stream.from(
x:1..5,
y:1..3
)
.filter
{
(x
+
y)
%
(x
+
2)
==
0
}
.map
{
x
+
y
}
!
assert
s.collect()
==
[
3,
4,
5,
6,
7
]