Paul,

side question, completely irrelevant to the original problem, just occurred to 
me when I read this...

> On 20. 5. 2024, at 17:02, Paul King <pa...@asert.com.au> wrote:
> println ([[x:1, y:100],  [x:2, y:1], [x: 2, y:500]].sort{ a, b -> a.x == b.x 
> ? a.y <=> b.y : a.x <=> b.x }) // works

Wouldn't sort { a,b -> a.x<=>b.x ?: a.y<=>b.y } be both more efficient and 
better readable and intention-revealing? Or do I overlook some reason why it 
would be a bad idea?

Thanks,
OC

> 
> On Tue, May 21, 2024 at 12:52 AM Paul King <pa...@asert.com.au> wrote:
>> 
>> If you have only two dimensions, you'll get away with your solution
>> for small integer coordinate values. Here is a counter example with
>> integers:
>> 
>> println ([[x:  1, y: 69273666],  [x: 69273666, y: 1]].sort{[it.x,
>> it.y]}) // broken
>> println ([[x:  1, y: 69273666],  [x: 69273666, y: 1]].sort{ a, b ->
>> a.x == b.x ? a.y <=> b.y : a.x <=> b.x }) // works
>> 
>> On Tue, May 21, 2024 at 12:25 AM M.v.Gulik <mvgu...@gmail.com> wrote:
>>> 
>>> 
>>> On Mon, 20 May 2024 at 15:40, Paul King <pa...@asert.com.au> wrote:
>>>> 
>>>> What sort result are you trying to achieve? There should be no need to
>>>> perform any recursion.
>>> 
>>> 
>>> Main target was reordering some set of randomly ordered x,y coordinates 
>>> into (for example*) a x,y(left to right, top to bottom) order (*:where any 
>>> of the actual sort directions could be easily flipped).
>>> 
>>> So far "*.sort{[it.y, it.x]}" seems the best and easiest way to do this 
>>> (despite its Float/Double caveat).

Reply via email to