4

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!

jerney
  • 2,187
  • 1
  • 19
  • 31
  • That's something you'd want to take up with MuleSoft directly. I'm sure they'd be grateful to know where one of their training modules states something incorrect. – jerney Jan 29 '19 at 14:17
  • You have the right idea, though. In your final code `orderBy` executes first, passing its output to the input of `filter`, which executes and then passes its output to the input of `groupBy`. Only way to get `groupBy` to execute first is to wrap it in parenthesis. – jerney Jan 29 '19 at 14:18

1 Answers1

6

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.

enter image description here

machaval
  • 4,969
  • 14
  • 20
  • @jerney This ast can be generated using the intellij data-weave plugin. Ping me and I can show you how – machaval Jan 31 '19 at 13:41
  • Still don't have access to the slack... will DM you on twitter, since that's the only way I know how to reach you :) – jerney Jan 31 '19 at 17:06