简体   繁体   中英

Precedence in multiple DataWeave functions

I'm going through the Mule Dev 1 course and am stumped between module content and what I'm seeing in practice.

The module content states that:

"When using a series of functions, the last function in the chain is executed first."

So

filghts orderBy $.price filter ($.availableSeats > 30) 

would "filter then orderBy".

However, I'm seeing that this statement:

payload.flights orderBy $.price filter $.price < 500 groupBy $.destination

actually does NOT execute groupBy first. In fact, placing the groupBy anywhere else throws an error (since the schema of the output after groupBy is changed).

Any thoughts here on why the module states the last function is executed first when that's clearly seems not the case?

Thanks!

The precedence is all the same for (orderBy, groupBy, etc). So it will first do the orderBy by price then it will filter it by price and last it will groupBy destination.

This is the same for dw 1 (mule 3.x) and dw 2 ( mule 4.x). Now the difference between this to versions of DW is that in DW1 all this used to be lang operators but in DW 2 are just functions that are called using infix notation. So this mean that you can just write the same using the prefix notation

filter(
       orderBy(filghts, (value, index) -> value.price), 
                           (value, index) -> value.availableSeats > 30) 

Just to show you this is the AST of this expression.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM