Skip to content

Commit

Permalink
Stream now implements Iterable<T> v0.5.4
Browse files Browse the repository at this point in the history
This means it can be used more easily with javarx for example
  • Loading branch information
Tim Yates committed Feb 14, 2013
1 parent 49e3547 commit 91c6e93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -15,7 +15,7 @@ sourceCompatibility=1.6
targetCompatibility=1.6

group = 'com.bloidonia'
version = '0.5.3'
version = '0.5.4'

repositories {
mavenCentral()
Expand Down
3 changes: 2 additions & 1 deletion src/main/groovy/groovy/stream/Stream.groovy
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions 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:
Expand All @@ -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.