Cool article by Grzegorz Piwowarek about writing a gatherer, and then optimizing it:

https://4comprehension.com/java-last-gatherer/

Implementing Efficient Last Stream Elements Gatherer in Java - { 4Comprehension }

Gatherers is the missing piece of the Stream API. So far, if we were missing a terminal method, we could always implement one ourselves by…

{ 4Comprehension }