Contact Us 1-800-596-4880

then

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

Name Description

previous

The value of the preceding expression.

callback

Callback that processes the result of previous if the result is not null.

Example

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

Source

%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

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