For the More Curious: Aggregating Data
We have shown a small set of the functional programming APIs that exist in Kotlin. There is another group of functions called aggregation functions that can reduce the entire contents of a collection into a single value. The best known of these functions is called reduce, and there is a similar function called fold.
reduce
reduce accumulates all values in a given collection into a single output value. The reduce function accepts a single lambda expression. This lambda expression takes in two parameters: A running aggregated value, called the accumulator, and the next value in the collection to aggregate. The return value from this lambda expression will be used as the next value for the ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.