---
title: REDUCE
url: https://www.tines.com/docs/formulas/functions/reduce/
kind: formula-function
---

*[tines.com](https://www.tines.com/llms.txt) › [Docs](https://www.tines.com/llms.txt) › [Formulas](https://www.tines.com/llm/docs/formulas.md) › [Functions](https://www.tines.com/llm/docs/formulas/functions.md)*

# REDUCE

*[View on tines.com](https://www.tines.com/docs/formulas/functions/reduce/)*

Iterates over elements in an array, applying a specified lambda function to accumulate a result. This function takes 3 arguments

`array`: The iterable to be reduced.

`LAMBDA`: A lambda function with two arguments (`previous` and `current`) that defines the reduction operation. Optionally, an expression `[expr]` can be included for additional computation.

`initial_value`: an initial value for the accumulator. The reduction starts with this value.

**Categories:** Lambdas

## Syntax

```
REDUCE(array, LAMBDA(previous_value, current_value, [expr]), initial_value)
```

## Examples

### Example 1

Input:

```json
{
  "my_array": [
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10
  ]
}
```

Formula:

```
REDUCE(my_array, LAMBDA(previous_value, current_value, PLUS(previous_value, current_value)), 0)
```

Output:

```json
55
```

### Example 2

Input:

```json
{
  "array_of_objects": [
    {
      "timestamp": "2022-02-15 12:30:00+0000"
    },
    {
      "user": "bob.smith"
    },
    {
      "src_ip": "192.168.1.100"
    },
    {
      "dest_ip": "172.16.1.23"
    },
    {
      "file_hash": "2968896cb4639d4c839ab802720266d35bb15be93e3a4055109aa3bf1779f591"
    },
    {
      "file_name": "executable.exe"
    }
  ]
}
```

Formula:

```
REDUCE(array_of_objects, LAMBDA(previous_value, current_value, MERGE(previous_value, current_value)), OBJECT())
```

Output:

```json
{
  "dest_ip": "172.16.1.23",
  "file_hash": "2968896cb4639d4c839ab802720266d35bb15be93e3a4055109aa3bf1779f591",
  "file_name": "executable.exe",
  "src_ip": "192.168.1.100",
  "timestamp": "2022-02-15 12:30:00+0000",
  "user": "bob.smith"
}
```

## Sample actions

```json
{
  "standardLibVersion": "13",
  "actionRuntimeVersion": "1",
  "agents": [
    {
      "disabled": false,
      "name": "REDUCE",
      "description": "",
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "message": "=REDUCE(my_action.vals, LAMBDA(previous_value, current_value, MERGE(previous_value, current_value)), OBJECT())"
        }
      },
      "position": {
        "x": -6900,
        "y": -1515
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "form": null
    },
    {
      "disabled": false,
      "name": "My Action",
      "description": null,
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "vals": [
            {
              "name": "martin"
            },
            {
              "location": "ireland"
            }
          ]
        }
      },
      "position": {
        "x": -6900,
        "y": -1635
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "form": null
    }
  ],
  "links": [
    {
      "sourceIdentifier": 1,
      "receiverIdentifier": 0
    }
  ],
  "diagramNotes": []
}
```
