Plaster

common-lisp
(defun find-best (predicate list &key (key #'identity)) "PREDICATE should return non-nil if its first argument is 'better' than its second argument." (let ((best (first list))) (loop :for item :in (rest list) :when (funcall predicate (funcall key item) (funcall key best)) :do (setf best item)) best)) (find-best #'> '() :key #'second) => NIL (find-best #'> '((a 1)) :key #'second) => (A 1) (find-best #'> '((a 2) (b 3) (c 1)) :key #'second) => (B 3)