Browse files

Stream now implements Iterable<T> v0.5.4

This means it can be used more easily with javarx for example
  • Loading branch information...
1 parent 49e3547 commit 91c6e936ba282232626741e5d9d392138d483e92 @timyates committed Feb 14, 2013
Showing with 21 additions and 2 deletions.
  1. +1 −1 build.gradle
  2. +2 −1 src/main/groovy/groovy/stream/Stream.groovy
  3. +18 −0 src/test/groovy/groovy/stream/StreamTests.groovy
View
2 build.gradle
@@ -15,7 +15,7 @@ sourceCompatibility=1.6
targetCompatibility=1.6
group = 'com.bloidonia'
-version = '0.5.3'
+version = '0.5.4'
repositories {
mavenCentral()
View
3 src/main/groovy/groovy/stream/Stream.groovy
@@ -100,7 +100,7 @@ package groovy.stream
*
* @author Tim Yates
*/
-public class Stream<T> implements StreamInterface<T> {
+public class Stream<T> implements StreamInterface<T>, Iterable<T> {
private static enum StreamType { MAP, OTHER }
private StreamInterface wrapped
private StreamType type
@@ -131,6 +131,7 @@ public class Stream<T> implements StreamInterface<T> {
*/
public int getStreamIndex() { wrapped.streamIndex }
+ public Iterator<T> iterator() { wrapped }
/**
* The starting point for a Stream taking a Map of Iterables to
* lazily return. The Stream will return all combinations of this map,
View
18 src/test/groovy/groovy/stream/StreamTests.groovy
@@ -1,5 +1,7 @@
package groovy.stream
+import spock.lang.Unroll
+
public class StreamTests extends spock.lang.Specification {
def "test Streaming a List Stream"() {
setup:
@@ -10,4 +12,20 @@ public class StreamTests extends spock.lang.Specification {
then:
result == [ 1, 2, 3 ]
}
+
+ @Unroll("#name are both an Iterator and an Iterable")
+ def "iterator/iterable tests"() {
+ expect:
+ stream instanceof Iterable
+ stream instanceof Iterator
+ stream.iterator().is( stream )
+
+ where:
+ name << [ 'closure streams', 'map streams', 'range streams' ]
+ stream << [
+ Stream.from( { x++ } ).using( [ x:1 ] ),
+ Stream.from( a:1..3, b:2..4 ).map { a + b },
+ Stream.from( 1..4 ).filter { it % 2 == 0 }
+ ]
+ }
}

0 comments on commit 91c6e93

Please sign in to comment.