Skip to content

Commit 73c31ac

Browse files
committed
implement to stream with bounded function in enumerator
1 parent 68828d3 commit 73c31ac

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

core/src/main/java/fj/data/Enumerator.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package fj.data;
22

3-
import fj.F;
3+
import fj.*;
44

55
import static fj.Function.*;
66
import static fj.data.Option.none;
77
import static fj.data.Option.some;
88

9-
import fj.Function;
10-
import fj.Ord;
11-
129
import static fj.Ord.*;
13-
import fj.Ordering;
1410
import static fj.Ordering.*;
1511

1612
import java.math.BigDecimal;
@@ -185,6 +181,18 @@ public Stream<A> toStream(final A a) {
185181
return Stream.fromFunction(this, id, a);
186182
}
187183

184+
/**
185+
* Returns a stream of the values from this enumerator,
186+
* starting at the min of given Bounded, ending at the max, counting up.
187+
*
188+
* @param bounded A value at which to begin the stream.
189+
* @return a stream of the values from this enumerator, cut by bounded, counting up.
190+
*/
191+
public Stream<A> toStream(final Bounded<A> bounded) {
192+
final F<A, A> id = identity();
193+
return Stream.fromFunction(this, id, bounded.min()).takeWhile(item -> !item.equals(bounded.max()));
194+
}
195+
188196
/**
189197
* Create a new enumerator with the given minimum value.
190198
*

0 commit comments

Comments
 (0)