Dataweave
How to enable streaming in Dataweave?
Dataweave doesn’t enable the streaming by default and we have to explicitly direct it to pass the data as stream. This enable faster processing of data where large amount of data need to be processed
Enable streaming while transforming and passing the data to next processor
%dw 2.0 output application/json deferred = true --- payload
more info – https://docs.mulesoft.com/dataweave/latest/dataweave-streaming#stream_output
Reduce function and it’s usage in Dataweave?
The reduce function in DataWeave is used to apply a function to each element of an array, accumulating the results into a single value. Here the reduce function will loop on items in the item array and store the values in acc in each iteration. If acc intial value is not defined then it will take the first value of the item array.
%dw 2.0 output application/json var numbers = [1, 2, 3, 4, 5] --- numbers reduce ((item, acc) -> acc + item)
Output = 15
with intial value defined for acc
%dw 2.0 output application/json var numbers = [1, 2, 3, 4, 5] --- numbers reduce ((item, acc = 3) -> acc + item)
Output = 18