Streams

Sam Pullara sam at sampullara.com
Thu Sep 13 22:23:08 PDT 2012


Here are some issues that I find with the current Streams implementation:

1) Collection is not a Stream. This means that whenever you use
collections and want to use some of the great new features you have to
first convert it to a stream:

list.stream().map(l -> parseInt(l)).into(new ArrayList<>())

I find this unnecessary. Collection could implement Stream and the
default methods could do the conversion for me, probably by calling
.stream() as above.

2) Optional should implement more of the Stream API like flatMap and
some others.

Option<U> flatMap(Mapper<T, ? extends Optional<U>>)

I also hate that with Optional.none() often needs to be witnessed and
not a big fan of using a constructor for Optional:

return matcher.matches() ? new Optional<>(matcher) : Optional.<Matcher>empty();

should really be something more like (using static imports):

return matcher.matches() ? option(matcher) : none();

3) I really, really believe that we should have something around
Future like I have prototyped here:

https://github.com/spullara/java-future-jdk8/blob/master/src/main/java/spullara/util/concurrent/Promise.java

Blocking to get the result of a Future is a bad code smell in my mind
after using Promises for a long time at Twitter. This will be a great
opportunity to get all the APIs in line with a much better way of
handling asynchronous work that isn't CPU bound.

Sam


More information about the lambda-spec-observers mailing list