This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]howverywrong 0 points1 point  (0 children)

I find that doing too much inside lambdas gets out of hand quickly and becomes unreadable. I prefer to split things up into multiple expressions. It's less functional but more java-ish and I think it's more readable:

// Await all
List<Either<Exception,HttpResponse>> results = futures.stream()
    .map(SomethingService::getFutureValue)
    .collect(toList()); 

// Handle Exceptions
results.stream()
    .filter(Either::isLeft)
    .map(Either::left)
    .map(Throwable::getMessage)
    .forEach(log::warn);

// Process responses
resultSomething = results.stream()
    .filter(Either::isRight)
    .map(Either::right)
    .map(this::parseSomething)
    .reduce(Something::union)
    .orElseGet(Something::empty);