Function to discard repeats, applied to numbers Solving a 4Clojure problem, I got this answer to compress a sequence (problem 30):

#(map first (partition-by identity %))


What would be the best approach to have this work with plain numbers too?

My solution was this:

(defmulti comp class)
(defmethod comp java.lang.Long [x] x)
(defmethod comp :default [x] (map first (partition-by identity %)))


The code is more than tripled.
Are there better solutions? Shorter? More idiomatic?
I tried extending java.lang.Long with ISeqable, but failed miserably.
Nice solution. Your solution already works great with sequences of numbers (and more) already. The comp multi-method is not a good idea. It is a function which can take either a seq or a number. You should avoid creating functions that take arguments that can be different types (it is confusing and suggests your might be better off with 2 functions or a protocol) unless there is a really good reason. In this case comp does not add anything useful (why did you add it? do you have an example use case?)