factor/extra/sorting/extras/extras.factor

14 lines
468 B
Factor
Raw Normal View History

2013-07-24 13:24:13 -04:00
USING: arrays assocs kernel kernel.private sequences
sequences.private sorting ;
2012-08-06 13:59:40 -04:00
IN: sorting.extras
: argsort ( seq quot: ( obj1 obj2 -- <=> ) -- sortedseq )
[ dup length iota zip ] dip
[ [ first-unsafe ] bi@ ] prepose
2012-09-19 13:23:58 -04:00
sort [ second-unsafe ] map! ; inline
: map-sort ( ... seq quot: ( ... elt -- ... key ) -- ... sortedseq )
2013-07-24 13:24:13 -04:00
[ map ] curry keep zip
[ { array } declare first-unsafe ] sort-with
[ { array } declare second-unsafe ] map ; inline