Varargs stream factory methods

Sam Pullara spullara at gmail.com
Sat Apr 20 10:02:12 PDT 2013


I like the .of() idea better than overloading .stream().

Sam

On Apr 20, 2013, at 8:47 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

> Currently we have, in Arrays:
>
>    public static <T> Stream<T> stream(T[] array) {
>        return stream(array, 0, array.length);
>    }
>
>    public static IntStream stream(int[] array) {
>        return stream(array, 0, array.length);
>    }
>
> etc.
>
> We *could* make these varargs methods, which is useful as creating ad-hoc stream literals:
>
>  Arrays.stream(1, 2, 4, 8).map(...)
>
> The downside is that we would have to lose (or rename) methods like:
>
>    public static IntStream stream(int[] array,
>                                   int fromIndex, int toIndex) {
>
> since stream(1, 2, 3) would be ambiguous.
>
> Probably better, make these static factories in the various stream interfaces:
>
>  Stream.of("foo", "bar")
>
>  IntStream.of(1, 2, 4, 8)
>


More information about the lambda-libs-spec-experts mailing list