
The lambda is executed for the first element, then the second element, and so on, until it's executed for each element in the collection. This works similarly to the repeat() function, or a for loop. The forEach() function executes the function passed as a parameter once for each item in the collection. The first higher-order function that you learn about is the forEach()function.


In the process, you'll get additional practice working with lambda expressions. In this codelab, you'll learn about a variety of functions that can be used on collection types, including forEach(), map(), filter(), groupBy(), fold(), and sortedBy(). Now that you have a solid foundation working with collections, it's time to revisit higher-order functions. Higher-order functions are especially relevant to collections as they help you perform common tasks, like sorting or filtering, with less code. In the Use function types and lambda expressions in Kotlin codelab, you learned about higher-order functions (functions that call other functions), such as repeat().
