Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8198620

New Convenient-Methods for java.util.stream.Stream

    Details

      Description

      A DESCRIPTION OF THE REQUEST :
      I really like the power of the stream API, but it would be helpful to have some convenient methods, to further reduce the length of code. All of them are only shortcuts for already existing functionality.

      Given the following Example-Stream:

      final Stream<Number> numbers = ...

      1. ofClass(<class>)

      numbers.ofClass(Double.class).
      This would be the equivalent to
      numbers.filter(Double.class::isInstance).map(Double.class::cast)
      Of course this could be reduced to one operation with a flatmap-function, but this would every project have to do and is still not as intuitiv.

      2. toList / toSet
      numbers.toList()/toSet()
      This would be the equivalent to
      numbers.collect(Collectors.toList()/toSet())

      Cheers,
      Rainer

      JUSTIFICATION :
      Having written a lot of C#-Code where those methods are available it is not really intuitive and also quite long to write this functionality down.

      Especially the ofClass-method would be really handy since I have a ton of places in my applications where I have always those to methods (filter + map).


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                smarks Stuart Marks
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: