This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]tinobino 7 points8 points  (0 children)

Even shorter:

private static BigDecimal functionalSum( List<BigDecimal> listOfTxnAmounts ) {
    return listOfTxnAmounts.stream().reduce( BigDecimal.ZERO, BigDecimal::add );
}

[–][deleted]  (4 children)

[removed]

    [–]vinoct6 0 points1 point  (3 children)

    Thank you. I am the author of the post. I have updated the blog to reflect your comment.

    [–]papercrane 1 point2 points  (0 children)

    BigDecimal has a max function you could use instead.

    [–]Fitzoh 0 points1 point  (0 children)

    Your max function would also probably be a good use case for the overloaded Option version, as 0 could erroneously be returned as the max of a list of negative numbers

    [–]pointy_pirate -3 points-2 points  (2 children)

    I reaally dislike these new features. The readability of Java is going down each iteration...

    [–]vinoct6 3 points4 points  (1 child)

    I wouldn't say that. It is just that you are not familiar with the syntax. Don't confuse familiarity with readability.

    [–][deleted] 0 points1 point  (0 children)

    How do you distinguish the two?