---
schema_version: "1"
id: c8ab2b4973f7c90f7b9f315ebc67514d9b157c1342faa90bbd197c6e9c34ec40
title: then
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dw-core-functions-then.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dw-core-functions-then
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 1357a39d09a99f5e8b6b0d37cf526cb7a6931f665c2100f7c38c20f58ec6d878
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# then

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## then(value: Null, callback: (previousResult: Nothing) -> Any): Null

Helper function that enables `then` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._

## then<T, R>(previous: T, callback: (result: T) -> R): R

This function works as a pipe that passes the value returned from the preceding expression to the
next (a callback) only if the value returned by the preceding expression is not `null`.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>previous</code></p></td><td><p>The value of the preceding expression.</p></td></tr><tr><td><p><code>callback</code></p></td><td><p>Callback that processes the result of <code>previous</code> if the result is not <code>null</code>.</p></td></tr></tbody></table>

### Example

This example shows how to use `then` to chain and continue processing the result of the previous
expression.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
    "chainResult": ["mariano", "de Achaval"]
            reduce ((item, accumulator) -> item ++ accumulator)
            then ((result) -> sizeOf(result)),
    "referenceResult" : ["mariano", "de Achaval"]
                         map ((item, index) -> upper(item))
                         then {
                            name: $[0],
                            lastName: $[1],
                            length: sizeOf($)
                        },
    "onNullReturnNull": []
                reduce ((item, accumulator) -> item ++ accumulator)
                then ((result) -> sizeOf(result))
}
```

#### Output

```Json
{
   "chainResult": 17,
   "referenceResult": {
     "name": "MARIANO",
     "lastName": "DE ACHAVAL",
     "length": 2
   },
   "onNullReturnNull": null
 }
```
