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.

June 2017

M T W T F S S
    1234
567891011
1213141516 1718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 22nd, 2017 11:52 pm
Powered by Dreamwidth Studios