Hi,
I have a very simply code and need to make 2 things:
- create a first list that feet a condition
- create another list (exclusion) using the same condition
I would like to see how would you do using a single foreach please ?
a!localVariables( local!lst, local!goodVehicles: a!forEach( items: ri!vehicles, expression: if(and( fv!item.typeid = 1, fv!item.isavailable, not(fv!item.deleted) ), fv!item, {}, ) ), local!badVehicles: a!forEach( items: ri!vehicles, expression: if(and( fv!item.typeid = 1, fv!item.isavailable, not(fv!item.deleted) ), {}, append(local!lst, fv!item), ) ), { good: local!goodVehicles, bad: local!badVehicles } )
Discussion posts and replies are publicly visible
You are aware that append inside a foreach does not work? local!lst will stay the same empty list throughout all iterations.
Wouldn't difference() solve your problem? Means, have the first foreach and build the second list from the difference?
Thank you Stefan, yes Difference() works perfectly well in this example, but it was just an example.
How would you do (if possible) if you had to do it in a single foreach, appendind/removing items in/from lists ? ( I should have take an example where Difderence() is not applicable ;-) )
:-)
I would use the reduce function and a helper expression. I would use the parameter "initial" of reduce as a shared memory which I modify on each iteration.
Did that to implement a block based check sum algorithm for IBAN validation.
Thanks a lot Stefan.
I will take a look a it.