3 ms·
What about a get-or-throw that throws an exception if it can't find the key? You get the best of both worlds. (defn get-or-throw [m k] (or (
by islon 14y ago
What about a get-or-throw that throws an exception if it can't find the key? You get the best of both worlds.
(defn get-or-throw [m k]
(or
(get m k)
(throw (RuntimeException. (str "could't find key " k " in map " m)))))
I understand most people use the simpler (key map) or (map key) forms instead of get, but at least you have an option.