Cyber Tech

Teeing, a hidden gem in the Java API


public PriceAndRows getPriceAndRows(Cart cart) {
  return cart.getProducts()
      .entrySet()
      .stream()
      .map(CartRow::new)                                                              (1)
      .collect(Collectors.teeing(                                                     (2)
          Collectors.reducing(BigDecimal.ZERO, CartRow::getRowPrice, BigDecimal::add),(3)
          Collectors.toList(),                                                        (4)
          PriceAndRows::new                                                           (5)
      ));
}



Source : blog.frankel.ch

ASu
I am tech enthusiast and a keen learner, Currently pursuing Bachelors in Computer Science from University of Delhi
https://technewz.org

Leave a Reply

Your email address will not be published. Required fields are marked *