sorting.extras: adding map-sort for efficiently decorating, sorting, and undecorating a sequence.
parent
fdc43d0574
commit
9d6f2ad353
|
@ -1,7 +1,9 @@
|
|||
USING: kernel math.order sequences tools.test ;
|
||||
USING: kernel math math.order sequences tools.test ;
|
||||
IN: sorting.extras
|
||||
|
||||
{ { 0 2 1 } } [ { 10 30 20 } [ <=> ] argsort ] unit-test
|
||||
{ { 2 0 1 } } [
|
||||
{ "hello" "goodbye" "yo" } [ [ length ] bi@ <=> ] argsort
|
||||
] unit-test
|
||||
|
||||
{ 1 { 2 3 4 5 } } [ 1 { 1 2 3 4 } [ dupd + ] map-sort ] unit-test
|
||||
|
|
|
@ -5,3 +5,7 @@ IN: sorting.extras
|
|||
[ dup length iota zip ] dip
|
||||
[ [ first-unsafe ] bi@ ] prepose
|
||||
sort [ second-unsafe ] map! ; inline
|
||||
|
||||
: map-sort ( ... seq quot: ( ... elt -- ... key ) -- ... sortedseq )
|
||||
[ map ] curry keep zip [ second-unsafe ] sort-with
|
||||
[ first-unsafe ] map ; inline
|
||||
|
|
Loading…
Reference in New Issue