I hope there is a hope. I saw DO in some answers but I could not figure out how to add condition. At least it works and does not throw syntax error
%dw 2.0
output application/json
---
do {
{
n: 1
}
}
Mule does not have do-while concept. However it could be imitated with a little trick. The only one iterative (to emulate do) function is reduce but it has only one accumulator which is passed from itration to iteration. This only one variable should be used to accumulate results and to indicate end of iterations (to emulate while).
Simplest way is to use value as accumulator and sign as indicator. While accumulating summary value negative result indicates end of cycles.
%dw 2.0
var x=[1,2,3,4,5]
output application/json
---
-(x reduce (item, acc=0) -> if (item <4 and acc >= 0) acc + item else if (acc>0) -acc else acc)
Some complex object could be used to collect results and also have indicator of the end of cycle as part of the object
%dw 2.0
var x=[1,2,3,4,5]
output application/json
---
(x reduce (item, acc={sum:0}) -> if (item < 4 and acc.end==null ) (acc - 'sum' ++ {sum: acc.sum+item}) else ( acc ++ {end:true} )).sum
https://simpleflatservice.com/mule4/DoWhileImitation.html