mulesoft-labs / data-weave-rfc

RFC for the data weave language
13 stars 5 forks source link

Update syntax on matched branches #3

Open machaval opened 5 years ago

machaval commented 5 years ago

What should happen when there are sub branches on the update.

{foo: 123} update {
    case .foo -> {bar: true}
    case .foo.bar -> {sub: 123}
} 

In my opinion this case should return {foo: {bar:true}} and not {foo:{bar: {sub: 123}}} and hint a warning saying that case .foo.bar -> {sub: 123} this branch is never going to be executed.

I think the bottom problem is how we define the semantics of update.

a. It would go through the expression ({foo: 123}) tree and see what branch matches and updates that node with what ever the matcher returns. This is more like a tree pattern matcher mental model

b. Think of update as a sequential update expressions where they will be executed one after the other. Like a chain {foo: 123} update .foo with {bar: true} update .foo.bar with {sub: 123}

The way it was in my mind is more like a

jerneyio commented 5 years ago

That works for me. Need to also consider what might happen if the user tries to update the same node twice:

{foo: 123} update {
    case at .foo -> {bar: true}
    case at .foo -> {bar: false}
} 

In this case you can ignore the second .foo branch, returning {foo: {bar: true}}