You are here |
studiofreya.org | ||
| | | |
blog.jooq.org
|
|
| | | | With Java 8 being mainstream now, people start using Streams for everything, even in cases where that's a bit exaggerated (a.k.a. completely nuts, if you were expecting a hyperbole here). For instance, take mykong's article here, showing how to collect a Map's entry set stream into a list of keys and a list of values:... | |
| | | |
blog.scaledcode.com
|
|
| | | | A dive into chapter 52 of Effective Java | |
| | | |
konradreiche.com
|
|
| | | | Since most of the Java code I wrote in the past was on Android I was not able to enjoy too many Java 8 features yet. Though recently I wrote a microservice in Java using Spring Boot where I could make full use of lambdas and functional interfaces. The following method, for instance, returns the sum of all transactions for a specified instance by traversing their children. @RequestMapping(value = "/transaction/sum/{id}", method = RequestMethod.GET) BigDecimal Sum sum(@PathVariable long id) { List transactions = new ArrayList<>(); Transaction current = repository.find(id); while (current != null) { transactions.add(current); current = current.getChild(); } return transactions.stream().map(t -> t.getAmount()) .reduce(BigDecimal.ZERO, BigDecimal::add); } As someone who learned Haskell in his freshman year I cannot but love the simplicity. Also, because it is a very common way to express this statement in Ruby. The code above the return statement could not be more imperative and I was wondering whether there is a way to express this in a functional way, too. In Ruby we could possible implement it like this: | |
| | | |
mydeveloperplanet.com
|
|
| | In this blog, we are going to take a closer look at the Java 8 Streams API. We will mainly do so by means of examples. We will cover many operations and after reading this blog, you will have a very good basic understanding of the Streams API. Enjoy reading! 1. Introduction The Streams API... |