Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10028

Add support for type conversion from Stream to array/collection/list/set

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.0-beta-1
    • groovy-jdk
    • None

    Description

      Consider the following:

      void test(source) {
        Number[] array = source
        println array.class
        println array
      
        Collection coll = source
        println coll.class
        println coll
      
        List list = source
        println list.class
        println list
      
        Set set = source
        println set.class
        println set
      }
      
      test(new int[] {1,2,3})
      test(Arrays.asList(1,2,3))
      test(Arrays.stream(1,2,3))
      

      Groovy supports automatic/implicit conversion from array to array/collection/list/set. And similarly for list to array or set (a list is already a collection/iterable). Can the type conversion logic be extended to support java.util.stream.Stream as a source for array/collection/list/set to eliminate the need for ".toArray()", ".toList()", ".toSet()" and ".collect(...)" in common situations?

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h