sorting.slots: make sort-keys-by and sort-values-by support hashtables.
parent
6649e4a426
commit
46d4b33349
|
@ -93,3 +93,8 @@ TUPLE: tuple2 d ;
|
||||||
{ { 3 { 2 4 } } { 1 { 2 0 0 0 } } { 0 { 1 } } { 1 { 1 } } }
|
{ { 3 { 2 4 } } { 1 { 2 0 0 0 } } { 0 { 1 } } { 1 { 1 } } }
|
||||||
{ length-test<=> <=> } sort-values-by
|
{ length-test<=> <=> } sort-values-by
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
{ { { "apples" 1 } { "bananas" 2 } { "cherries" 3 } } } [
|
||||||
|
H{ { "apples" 1 } { "bananas" 2 } { "cherries" 3 } }
|
||||||
|
{ { sequences:length <=> } } sort-keys-by
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2009 Slava Pestov, Doug Coleman.
|
! Copyright (C) 2009 Slava Pestov, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays fry kernel math.order sequences sorting ;
|
USING: arrays assocs fry kernel math.order sequences sorting ;
|
||||||
IN: sorting.slots
|
IN: sorting.slots
|
||||||
|
|
||||||
: execute-comparator ( obj1 obj2 word -- <=>/f )
|
: execute-comparator ( obj1 obj2 word -- <=>/f )
|
||||||
|
@ -23,6 +23,8 @@ IN: sorting.slots
|
||||||
|
|
||||||
: sort-by ( seq sort-specs -- seq' ) [ ] sort-by-with ;
|
: sort-by ( seq sort-specs -- seq' ) [ ] sort-by-with ;
|
||||||
|
|
||||||
: sort-keys-by ( seq sort-seq -- seq' ) [ first ] sort-by-with ;
|
: sort-keys-by ( alist sort-seq -- seq' )
|
||||||
|
[ >alist ] dip [ first ] sort-by-with ;
|
||||||
|
|
||||||
: sort-values-by ( seq sort-seq -- seq' ) [ second ] sort-by-with ;
|
: sort-values-by ( seq sort-seq -- seq' )
|
||||||
|
[ >alist ] dip [ second ] sort-by-with ;
|
||||||
|
|
Loading…
Reference in New Issue