stream

A collection of 6 posts

A Java geek
  • Me
  • Books
  • Speaking
  • Mentions
  • Focus
May 9, 2021 stream collector api

Teeing, a hidden gem in the Java API

Last week, I described a use-case for a custom Stream Collector. I received a intriguing comment on Twitter: There was a 'Not Found' error fetching URL: 'https://twitter.com/Miguucm/status/1389258245886390292' Hats off to you, Miguel! Your comment revealed a method I didn’t know! So I decided to investigate what the teeing() method is about. Returns a Collector that is a composite of two downstream collectors.

Nicolas Fränkel
May 2, 2021 stream collector api

A real-world example of a Stream Collector

Java Stream’s Collectors methods fit most use-cases. They allow returning either a Collection or a scalar. For the former, you use one of the toXXX() method, for the latter, one of the reducing() one. Let’s imagine an e-commerce platform that implements a shopping cart. The cart is modeled as the following: This diagram might translate into the following (abridged) code: Product.

Nicolas Fränkel
Feb 21, 2021 functional programming api optional stream

Optional.stream()

This week, I learned about a nifty 'new' feature of Optional that I want to share in this post. It’s available since Java 9, so its novelty is relative. Let’s start with the following sequence to compute the total price of an order: public BigDecimal getOrderPrice(Long orderId) { List<OrderLine> lines = orderRepository.findByOrderId(orderId); BigDecimal price = BigDecimal.ZERO; (1) for (OrderLine line : lines) { price = price.add(line.

Nicolas Fränkel
Nov 25, 2018 kotlin collection sequence stream lazy evaluation

Kotlin, collections and sequences

When streams were added to Java 8, I wanted to jump on the bandwagon. I read blog posts, watched videos, attended workshops to understand what this was all about. After a while, I became comfortable enough…​ but I was unhappy with the implementation: while streams offer methods with a functional approach, legacy collections do not. When one wants to use Java capabilities on an existing collection, the later needs to be transformed to a stream, and then back again.

Nicolas Fränkel
Nov 18, 2018 clojure sequence stream

Feedback on Learning Clojure: comparing with Java streams

This is the 7th post in the Learning Clojure focus series. Coming from a Java background, I’m currently trying to learn the Clojure programming language, with the help of online resources and mentorship. Some weeks ago, I tried to wire things together by trying to find equivalent methods to those available in Java streams. While I managed to get things working, writing working code and writing idiomatic code are two very different things.

Nicolas Fränkel
Nov 4, 2018 clojure sequence stream

Learning Clojure: comparing with Java streams

This is the 6th post in the Learning Clojure focus series. In general, one learns by comparing to what one already knows: I’m learning Clojure in that way. Coming from a Java background, I naturally want to use streaming features. So, what would be the Clojure counterparts of Java’s functions filter(), map(), etc.?

Nicolas Fränkel
A Java geek © 2008-2026
v. bc04c88300c3ec997ce8470fbff5395dc9e518b1/13264050981
Latest Posts