From the course: Elixir 101: Essential Functional Programming Techniques

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Advanced iterating

Advanced iterating

- [Instructor] In this video, I'll introduce you to the reduce function of the enum module. The reduce function can be challenging to wrap your head around but it is integral to the Elixir programming language. Reducers were first introduced in the Clojure language and the reduce operation is at the core of the enumerable protocol in Elixir and it brings powerful benefits to our code. You can think of a reducer as a function that takes an accumulator, transforms it in some way and returns an accumulator with the same type as the initial accumulator. On Branch 06_02b, open reduce.ex in the chapter six directory. In the example1 function is the reduce function of the Enum module. This function takes three arguments: a collection, an accumulator and a function. The function is called on each element of the collection and the result is returned as the accumulator for the next iteration. The final value of the…

Contents