From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Fold with Sum and Aggregate

Fold with Sum and Aggregate

- [Instructor] The concept we're looking at in this video is called fold, it's also called reduce in some languages, and in the dotnet, world and link, these are known as aggregate functions. So we've got aggregate sum, average, max, min, and count, those are some of the examples we'll look at. Now the idea of a fold is it applies a function to each item in the list, but it doesn't return a list, it returns a single value. It's also known as an accumulative function. So it performs the operation. And as it goes through the list, it accumulates the value that will be output at the end. So for example, in link, there's a sum function, the totals of first and second item, then it takes the results of that and totals that with the third item, and so on. So as it goes through the list, it's building up the sum, or it's building up the average, or it's counting the number of items that are in the list, or it's finding out which is…

Contents