commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita" <ki...@apache.org>
Subject [functor][FUNCTOR-14] Merge generators branch
Date Sat, 24 Aug 2013 16:52:38 GMT
Hi All, 

I would like to merge [functor]'s branch generators-FUNCTOR-14 [1], related to issue FUNCTOR-14
[2].

This the summary of the changes in that branch:

- New subpackage, o.a.c.functor.generator.loop
- New generator type added, LoopGenerator, that can be stopped
- The BaseGenerator has no long isStopped() or stop() methods. Both have been moved to the
LoopGenerator. 
- Ranges are no long generators
- New package o.a.c.functor.range
- Range extends Iterable and Iterator interfaces

The motivation for these changes were to be able to create generators that didn't have the
stoppable behaviour (thus the new package and type), and to be able to have simple ranges
in for loops.

Before the new range package, in order to iterate over the created range, you would have to
write a Procedure that would be used as a callback for each range element. Now, by extending
Iterable/Iterator you can do as follows:

+--snippet--+
Range<Integer, Integer> n = new IntegerRange(0, 10);
for (int i : n) {
        System.out.printf("%d ", i);
}
+--snippet--+


That produces 0 1 2 3 4 5 6 7 8 9 , or even a range like:

+--snippet--+

for (int i : Ranges.integerRange(0, BoundType.OPEN, 10, BoundType.OPEN, 2)) { // 2 is the
step
        System.out.printf("%d ", i);
}
+--snippet--+


That produces 2 4 6 8 .

Any thoughts/objections on this?

Thank you in advance!

[1] http://svn.apache.org/repos/asf/commons/proper/functor/branches/generators-FUNCTOR-14/
[2] https://issues.apache.org/jira/browse/FUNCTOR-14

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message