I have this list:
- ADD X
- ADD Y
- REMOVE Z
- ADD X
- NO ACTION Y
I need of this results:
- ADD X
- NO ACTION Y
- REMOVE Z
The rules to calculate the delta are these:
I have 3 action (ADD, REMOVE, NO ACTION)
- ANY ACTION * NO ACTION = NO ACTION
- ADD * REMOVE or REMOVE * ADD = NO ACTION
- SAME ACTION * SAME ACTION = SAME ACTION
The problem is that I implement this with a functional language (XQuery). I found a logic, based on fn:distinct-values. But the last rule (3) is unsatisfied.
Thanks in advance!!
Finally I found the way. I hope that this is good.
These are my first experiments with XQuery and I need to remeber what I have under my fingers and what possibilities this language offer.
My problem is data that came in. And I decide to transformate the information in a structure that can I easily manipulate.
A golden brick to solve this is this example about grouping data :
After this I used this algorithm:
0. If the count of action == 1 -> take first action
1. else If exist almost ONE – NO ACTION -> NO ACTION (RULE 1)
2. else If exist ADD and REMOVE in same list -> NO ACTION (RULE 2)
3. else take the first action (equal actions)
For this I borrowed a function from functx library:
Simple but effective.
Thanks a lot for all!