ivy: do correct associativity for scan

It's weird but those are the rules.
TODO: find a better algorithm.