sort-keys ( obj -- sortedseq ) (original) (raw)
sort-keys ( obj -- sortedseq )
Factor handbook » The language » Collections » Sequence operations » Sorting sequences
Prev: | inv-sort-by ( ... seq quot: ( ... elt -- ... key ) -- ... sortedseq ) |
---|---|
Next: | sort-values ( obj -- sortedseq ) |
Vocabulary
sorting
Inputs
obj | an object |
---|
Outputs
sortedseq | a new sorted sequence |
---|
Word description
Sorts the elements of obj (converting to an alist first if not a sequence), comparing first elements of pairs using the <=> word.
See also
compare, sort, sort-by, inv-sort-by, sort-values
Definition
GENERIC: sort-keys ( obj -- sortedseq )
Methods
USING: arrays assocs hashtables kernel.private sequences.private
sorting ;
M: hashtable sort-keys
>alist [ { array } declare first-unsafe ] sort-by ;
USING: assocs kernel sorting ;
M: object sort-keys >alist sort-keys ;
USING: sequences sequences.private sorting sorting.private ;
M: sequence sort-keys 0 check-bounds [ first-unsafe ] sort-by ;