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.

July 2017

M T W T F S S
     12
3456789
10111213141516
17 181920212223
24 252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 26th, 2017 04:28 am
Powered by Dreamwidth Studios