Cyber Tech

Teeing, a hidden gem in the Java API

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

Source :

I am tech enthusiast and a keen learner, Currently pursuing Bachelors in Computer Science from University of Delhi

Leave a Reply

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