From the course: Learning Higher-Order Functions with Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reduce
- The next higher order function we want to talk about is Reduce. Now, for some reason, a lot of people seem to have a problem getting the concept of Reduce. I know I did. Just like Map, you want to call it Convert. It converts, it converts. That's not necessarily, it's a little bit broader than that. You can do a lot more with it. Reduce is the same way. It takes a collection and produces one value, and that's it. Don't overthink it again. It's taking a bunch of things and coming out with one. That might mean it sums them together, might mean it concatenates them, it might mean it merges them together some other way, or takes them apart somehow. But the idea is, you take a bunch of things, and you come up with one value. So, you could call it boiling down. You could call it combining. You could call it reducing, and that's what it's called, Reduce. It takes a collection, produces one value. It has an initial starting value that's called the initial result, and then, each time your…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.