Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:46:15+00:00 2026-06-15T12:46:15+00:00

the motivation is for checking what has changed in a deeply nest map, kind

  • 0

the motivation is for checking what has changed in a deeply nest map, kind of like a reverse of update-in.

This is a simple example:

(def p1 {:a {:a1 :1 :a2 :2}
         :b {:b1 :1 :b2 :2}})

(def p2 (update-in p1 [:a :a1] (constantly :updated))
;; => {:a {:a1 :updated :a2 :2}
;;     :b {:b1 :1 :b2 :2}}

(what-changed? p1 p2) 
;; => {:keys [:a :a1] :value :updated)

(what-changed? p2 p1) 
;; => {:keys [:a :a1] :value :2)

I’m hoping that because clojure maps are persistent data-structures, there may be a smart algorithm to figure this out by looking at the underlying structure as opposed to walking through the nested maps and comparing the difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:46:17+00:00Added an answer on June 15, 2026 at 12:46 pm

    Persistent data structures is only about implementation and not about “looking at the underlying structure”.
    As Joost said (+1) you can use “diff”. It only needs to convert the answer using your “{:keys … :value …}” pattern:

    (def p1 {:a {:a1 :1 :a2 :2}
             :b {:b1 :1 :b2 {:b11 :11 :b22 :22}}})
    
    (def p2 {:a {:a1 :updated1 :a2 :2}
             :b {:b1 :1 :b2 {:b11 :updated2 :b22 :updated3}}})
    
    (defn what-changed?* [m]
      (if (not (map? m))
        [(list m)]
        (apply concat (map (fn [k]
                             (map (fn [nest-k]
                                    (conj nest-k k))
                                  (nested-keys (m k))))
                           (keys m)))))
    
    (defn what-changed? [m1 m2]
      (map (fn [l] {:keys (drop-last l) :value (last l)})
           (nested-keys (second (data/diff m1 m2)))))
    

    Test:

    (what-changed? p1 p2)
    -> ({:keys (:a :a1), :value :updated1}
        {:keys (:b :b2 :b11), :value :updated2}
        {:keys (:b :b2 :b22), :value :updated3})
    
    (what-changed? p2 p1)
    -> ({:keys (:a :a1), :value :1}
        {:keys (:b :b2 :b11), :value :11}
        {:keys (:b :b2 :b22), :value :22})
    

    BTW in your case you can modify hashmap by “assoc-in” instead of “update-in”:

    (assoc-in {:a {:a1 :1 :a2 :2}
               :b {:b1 :1 :b2 :2}}
              [:a :a1] :updated)
    -> {:a {:a2 :2, :a1 :updated}
        :b {:b2 :2, :b1 :1}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Here's a truly simple example. Motivation for this example below. This compiles: {-#
Motivation is kind of hard to explain so I'll provide an example: Assume you
Update: I deleted my motivation because it seems to distract readers. This is not
motivation: I would like to create a utility class so that instead of having
EDIT: To explain my motivation for this, I'm writing a command-line utility that takes
I understand the cultural diversity motivation behind this ICAN decision but how disruptive is
My motivation for this question is really just to specify an image to be
Motivation I'd like to find a way to take an arbitrary color and lighten
Motivation: I have a function func(const string& s); { //... } of course this
Motivation: I would like to construct an enum that represents all possible values for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.