Lambda Filters
Higher Order Filters operate on a list of items and process a Lambda individually for each item. The Lambda has access to several context variables that represent various states of the iteration process. Details of each of these context variables are mentioned below.map
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed
- $parent - the context variable that represents the entire array with all of its elements.

List of user objects.

Map filter used to transform the list of user objects

The result is the list of usernames.

some
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.

List of user objects.

every
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.

In this example, Every filter will determine if every price in the products array is greater than 10.
find
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.

In this example, the first product object with a price greater than 10 will be returned.
findIndex
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.

In this example, findIndex will return the first element index where the price is greater than 10.
filter
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.

In this example, filter will return all elements where the price is greater than 10.
reduce
- $this - the context variable that represents the element of the array being processed.
- $index - the context variable that represents the numerical index of the element of the array being processed.
- $parent - the context variable that represents the entire array with all of its elements.
- $result - the context variable that is used to represent the result of the previous iteration or the initial value on the first iteration.
$result
which can be referenced. The $result
variable is the state of the reduction process. The first time the Lambda runs, the $result
variable is the same as the initial variable. The return statement of the Lambda will be the $result
variable for the 2nd iteration and so forth until there are no iterations left. The final value of the $result
variable will be assigned to whatever is referencing the reduce filter.
The details above may feel like a mouthful, but things should start to click when seeing a few examples.
The most basic example would be sum a list of values.

Here's an example array of [1, 10, 100].

In this example, the reduce filter will result in a sum of the array or 111.

In this example, we have an array of objects.

Using the reduce filter in this example, we sum the values of num for each object resulting in 111.