Search code examples
clojurearity

Use of dissoc's unary version?


While using dissoc, I noticed it has a unary version which didn't seem to do anything. I checked the source, and it turns out it's just the identity function:

(defn dissoc
  ([map] map)
  ([map key]
   (. clojure.lang.RT (dissoc map key)))
  ([map key & ks]
   (let [ret (dissoc map key)]
     (if ks
       (recur ret (first ks) (next ks))
       ret))))

then I noticed that disj has a unary version as well with the same definition.

What is the purpose of the unary versions? The only potential use I can see is maybe when they're used with apply, but I don't see how this would be useful. And why don't their conj and assoc counterparts have similar unary versions?


Solution

  • Consider (apply dissoc some-map items-to-remove).

    If the unary form didn't exist, items-to-remove being empty would be an error, and thus one would need to always check its length before making this call.