Skip to content

Instantly share code, notes, and snippets.

@lukego
Created June 1, 2021 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukego/2bdacbaea35211f1c4fde99c74268ebf to your computer and use it in GitHub Desktop.
Save lukego/2bdacbaea35211f1c4fde99c74268ebf to your computer and use it in GitHub Desktop.
(defun same (key-fn list &key (test #'eql))
"True if KEY-FN returns the same value for every element of LIST.
Example: (same #'length '((a b c) (d e f) #(1 2 3))) => T"
(or (null list)
(loop with v = (funcall key-fn (first list))
for x in (rest list)
always (funcall test v (funcall key-fn x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment