On Sun, 24 May 2020, Elizabeth Mattijsen wrote:
> Hmmm... it appears we need to numerify the match to get numeric comparison 
> semantics, so we put a "+" before the match:
> 
> $ raku -e 'my @x=<a5 a2 a123 a133 a1>.sort: { +m/ \d+ $/ }; for @x { say $_; 
> }'
> a1
> a2
> a5
> a123
> a133
> 

So I think this would be a more general "version sort" then, where the number
doesn't have to be at the end only:

  @things.sort: {
      .comb(/ \d+ | \D+ /)
      .map({ .Int // .self })
  }

It does not conform to all the rules about natural sort on Rosetta Code [1]
but I like how

  - longest-token matching,
  - .sort behavior on (differently-sized) tuples, and
  - .Int returning an (undefined) Failure

work together here.

Regards,
Tobias

[1] https://rosettacode.org/wiki/Natural_sorting

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

Reply via email to