Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Key based sort. Not in public API yet.

  • Loading branch information...
commit 38673e93a16288776489757700716056ed43df8b 1 parent badad22
@gigamonkey authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 sorting.lisp
View
11 sorting.lisp
@@ -0,0 +1,11 @@
+(in-package :com.gigamonkeys.utilities)
+
+(defun keyed-sort (sequence predicate key)
+ "Sort `sequence' using `predicate' applied to the result of applying
+ `key' to each item, using the Schwarzian Transform so `key' is only
+ invoked once per item, rather than at each comparison."
+ (mapcar #'cdr
+ (sort
+ (mapcar (lambda (x) (cons (funcall key x) x)) sequence)
+ predicate :key #'car)))
+
Please sign in to comment.
Something went wrong with that request. Please try again.