Hi,

On May 19, 3:25 pm, Russell Christopher
<russell.christop...@gmail.com> wrote:

> slight error w/ the previous, local-get-in should have been local-get
>
> (defn get-in
>  ([m ks]
>   (get-in m ks nil))
>  ([m ks not-found]
>   (letfn [(local-get [nf m ks] (get m ks nf))]
>            (reduce (partial local-get not-found) m ks))))

Going to the metal:

(defn get-in
  ([m ks]
   (get-in m ks nil))
  ([m ks not-found]
   (if-let [[k & ks] (seq ks)]
     (let [candidate (get m k not-found)]
       (if (identical? candidate not-found)
         not-found
         (recur candidate ks not-found)))
     not-found)))

So we stop in the key sequence when an intermediate step
is not contained in the nested structure. Remains the
question whether an empty key sequence is an error.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to