I don't know exactly what is happening and didn't look into any debug output but it looks like for ternary expression closure the compiler is having trouble inferring $0 and $1 as CatWithCount. Type annotate the closure may workaround the issue
Slowness of the ternary infamous unfortunately, it was even recently mentioned during review of if/switch expressions. There just be an issue open for that already on GitHub, but if you can't find one please feel free to open it.
($0.count, $1.cat) > ($1.count, $0.cat). That doesn't work for me as if the counts are equal, I want the one with the lowest category ID to sort first. But thanks as I didn't know you could do that with tuples.
What would be nice is the ability to creates sorts like this (with totally fictitious syntax)
.sorted { (>(\count), <(\cat)) }
allObjects - Thanks - I lived in the Objective C world for too long
I'm confused as yes, that produces the expected result, but it doesn't seem to match what the documentation says for the tuple > operator:
" Given two tuples (a1, a2, ..., aN) and (b1, b2, ..., bN) , the first tuple is after the second tuple if and only if a1 > b1 or (a1 == b1 and (a2, ..., aN) > (b2, ..., bN) )."