Mar. 14th, 2016

jbanana: Badly drawn banana (Default)
I was trying to get my head round Java 8 streams. Here's a typical example:
List<Integer> transactionsIds = transactions.stream()
         .filter(t -> t.getType() == Transaction.GROCERY)
         .sorted(comparing(Transaction::getValue).reversed())
         .map(Transaction::getId)
         .collect(toList());
"Get the grocery transactions, largest value first, and tell me their IDs."

So this seems cool, and you can make a stream parallel, so it might be a good way to implement a lot of things.

The lightbulb came on when I realised that you can only apply a predefined set of operations. The thing you're calling methods on is the stream, not the contents. So you might be able to re-write existing code in terms of filter, map, etc. but you can't just drop an existing chunk of code into a stream and get magic.

August 2025

M T W T F S S
    123
45678910
11121314151617
1819202122 2324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 16th, 2025 04:15 pm
Powered by Dreamwidth Studios