The first()
function on a List
is an example of functional programming.
first()
is a function that takes a lambda expression as a parameter. A
lambda expression is simply a way of representing an anonymous function.
first()
uses the lambda expression, calling it to evaluate the items
in the list. Specifically, first()
iterates through the list until
the lambda expression returns true
for an item in the list (or until first()
reaches the end of the list).
Functions like first()
are called higher-order functions: functions that
take functions (e.g., lambda expressions) as parameters.
You can learn more about this in:
Tags: