Sunday, May 9, 2021

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)
      ));
}


from Hacker News https://ift.tt/3f92PLE

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.