fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 240: Sort 2 lists together
Idiom # 240: Sort 2 lists together
See
programming-idioms.org
:
Code
sort list b based on the sorting of list a
s := a.zip b x,y->(x,y) .sort_by (x,y -> x.0 <= y.0) a := s.map v->v.0 b := s.map v->v.1
What are effects?
Running Example
ex240 is a0 := [ "siebenundvierzig", "elf", "null", "acht", "fünfzehn" ] b0 := [ "47", "11", "0", "8", "15" ] s := a0.zip b0 x,y->(x,y) .sort_by (a,b -> a.0 <= b.0) a1 := s.map v->v.0 b1 := s.map v->v.1 say a1 say b1 # NYI: With more syntax sugar for tuples, this should be: # # s := a.zip b x,y->(x,y) # .sort_by x->x.0 # a := s.map v->v.0 # b := s.map v->v.1
What are effects?
last changed: 2024-07-01
next: NYI: Idiom # 241: Yield priority to other threads