Functional Programming - Sum

Card Puncher Data Processing

About

The addition (sum) function in a Functional programming context

Snippet

Java

Stream

  • From a collection of object that return an exit status
Integer errors = insertStreamListeners
                .stream()
                .mapToInt(s -> s.getExitStatus()>0?1:0)
                .sum();
  • Where myMao is map where the values are integers
Integer tot = myMap
    .values()
    .stream()
    .mapToInt(s->s)
    .sum()





Discover More
Card Puncher Data Processing
What is Functional programming (FP) - Collection Operations

In Functional programming (FP), you will pass functions to other functions as parameters. It is a declarative paradigm that treats computation as the evaluation of mathematical functions. With functional...



Share this page:
Follow us:
Task Runner