🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
tonyo m: enum A <A1 A2 A3>; sub a (A:D $a) { say $a == A2; }; a(A1); a(A2); # tbrowder__ ?? 16:22
camelia False
True
Xliff_ \o 17:14
What'
What's the best way to do multi-key sorting in Raku? 17:15
Voldenet just sort by them both 17:23
m: my $x = [{ :a(1) :b(2) }, { :a(1) :b(1) }, { :a(1) :b(-1) }, { :a(-1) :b(2) }]; say $x.sort(*<b>).sort(*<a>)
camelia ({a => -1, b => 2} {a => 1, b => -1} {a => 1, b => 1} {a => 1, b => 2})
Voldenet iirc sort is stable
just sort by attributes in reversed order, so `order by a, b` becomes `.sort(*<b>).sort(*<a>)` 17:25
Xliff_ Or you can just use a list. :) 17:33
Voldenet++
tonyo isn't that ordering by just a? 17:34
b=2,1,1,2, a=-1,1,1,1 doesn't look like it's order by b, a 17:35
m: my $x = [{ :a(1) :b(2) }, { :a(1) :b(1) }, { :a(1) :b(-1) }, { :a(-1):b(2) }]; say $x.sort({ $^a<a> cmp $^b<a> ~~ Same ?? $^a<b> cmp $^a<b> !! $^a<a> cmp $b<a>}); 17:38
camelia ({a => -1, b => 2} {a => 1, b => 2} {a => 1, b => 1} {a => 1, b => -1})
Voldenet oh, using a list works too 17:56
librasteve yeah - I thought that
there has to be a better way than this ?!
Voldenet m: my $x = [{ :a(1) :b(2) }, { :a(1) :b(1) }, { :a(1) :b(-1) }, { :a(-1) :b(2) }]; say $x.sort(*<a b>) 17:57
camelia ({a => -1, b => 2} {a => 1, b => -1} {a => 1, b => 1} {a => 1, b => 2})
Voldenet obviously
librasteve ++ 18:00
Voldenet or
Voldenet m: my $x = [{ :a(1) :b(2) }, { :a(1) :b(1) }, { :a(1) :b(-1) }, { :a(-1) :b(2) }]; say $x.sort({ $_<a>, $_<b> }) 18:00
camelia ({a => -1, b => 2} {a => 1, b => -1} {a => 1, b => 1} {a => 1, b => 2})
librasteve wrong! 18:04
what is the $ in $<a> ?? 18:05
oh, sorry maybe the bridge dropped a * or an 18:07
Voldenet `my $x = [{ :a(1) :b(2) }, { :a(1) :b(1) }, { :a(1) :b(-1) }, { :a(-1) :b(2) }]; say $x.sort({ $_<a>, $_<b> })` 18:09
the bridge will inevitably drop underscores and whateverstars
librasteve alles klar
tx 18:10
Nemokosch well it treats them as markdown 18:21
tonyo Voldenet++ , didn't know you could do that 21:31