Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      Apparently, the Generator API in [functor] was created based on Python generators. However, there is room for enhancements in the current implementation.

      The Generator interface contains methods to stop its execution. However not all generators are necessarily 'stoppable'. Maybe we could move this behavior to a separate interface.

      The parameters passed to a generator (from, to, step) are the same that, in Python, can be used to create a Range. Ranges are used in many examples of Generators in Python. We could include Ranges in [functor] and utilize them in Generators. It would be good if we could include/exclude the Range boundary values, i.e. we could create a Range 0..2, and define 0 or 2, as being either inclusive or exclusive.

      Among the current generators, there is one for Integer's, and another one for Long's. We could create generators for other types too (e.g.: Char, Date, Double, Float, ...).

      Another feature usually related to Generators in Python is the yield statement. There are some API's in Java that provide a yield implementation. This is not entirely necessary, but could be convenient to include it to [functor] too, combined with Generators. Maybe in [functor] we could create a YieldProcedure. This way, the Generator would yield its values to this procedure. Just food for thought.

      This issue is quite vague, so feel free to add comments, or criticize. This way we can achieve a common consensus on a new and awesome Generator API for [functor]. No hard feelings

      Cheers

        Activity

        Hide
        simone.tripodi Simone Tripodi added a comment -

        any chance to get a patch also for this?

        Show
        simone.tripodi Simone Tripodi added a comment - any chance to get a patch also for this?
        Hide
        kinow Bruno P. Kinoshita added a comment -

        Sure thing, I'll resync my code with the SVN and will start to work on this. Many thanks Simo!

        Show
        kinow Bruno P. Kinoshita added a comment - Sure thing, I'll resync my code with the SVN and will start to work on this. Many thanks Simo!
        Hide
        kinow Bruno P. Kinoshita added a comment -

        Created a branch in SVN to work on this issue.

        Author: kinow
        Date: Thu Aug 16 19:09:10 2012
        New Revision: 1373984

        URL: http://svn.apache.org/viewvc?rev=1373984&view=rev
        Log:
        Creating a branch to work on FUNCTOR-14 issue: Enhancements on the Generator API

        Show
        kinow Bruno P. Kinoshita added a comment - Created a branch in SVN to work on this issue. Author: kinow Date: Thu Aug 16 19:09:10 2012 New Revision: 1373984 URL: http://svn.apache.org/viewvc?rev=1373984&view=rev Log: Creating a branch to work on FUNCTOR-14 issue: Enhancements on the Generator API
        Hide
        kinow Bruno P. Kinoshita added a comment -

        Author: kinow
        Date: Thu Sep 12 04:29:46 2013
        New Revision: 1522355

        URL: http://svn.apache.org/r1522355
        Log:
        FUNCTOR-14 Merge branch generators-FUNCTOR-14. Adding the loop and range packages, and simplifying the BaseGenerator type.

        Added:
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/package-info.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/BoundType.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/CharacterRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/DoubleRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Endpoint.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/FloatRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/IntegerRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Range.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Ranges.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/package-info.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestEndpoint.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java
        Removed:
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java
        Modified:
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryPredicate.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java
        commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/EachElement.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java
        commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
        commons/proper/functor/trunk/src/changes/changes.xml
        commons/proper/functor/trunk/src/site/xdoc/examples.xml

        Show
        kinow Bruno P. Kinoshita added a comment - Author: kinow Date: Thu Sep 12 04:29:46 2013 New Revision: 1522355 URL: http://svn.apache.org/r1522355 Log: FUNCTOR-14 Merge branch generators- FUNCTOR-14 . Adding the loop and range packages, and simplifying the BaseGenerator type. Added: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateUntil.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/GenerateWhile.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/LoopGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/TransformedGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/UntilGenerate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/WhileGenerate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/package-info.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/BoundType.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/CharacterRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/DoubleRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Endpoint.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/FloatRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/IntegerRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Range.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/Ranges.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/package-info.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestIteratorToGeneratorAdapter.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestEndpoint.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java Removed: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/GenerateUntil.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/GenerateWhile.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/IteratorToGeneratorAdapter.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/TransformedGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/UntilGenerate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/WhileGenerate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/LongRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestIteratorToGeneratorAdapter.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryPredicate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/adapter/FullyBoundNullaryProcedure.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/IndexOfInGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/BaseGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/FilteredGenerator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/EachElement.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/lines/Lines.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/map/FixedSizeMap.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java commons/proper/functor/trunk/src/changes/changes.xml commons/proper/functor/trunk/src/site/xdoc/examples.xml

          People

          • Assignee:
            kinow Bruno P. Kinoshita
            Reporter:
            kinow Bruno P. Kinoshita
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development