• Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Declined
    • Affects versions: None
    • Fix versions: None
    • Labels:
    • Approval:
    • Patch:
      Code and Test


      To the topic of get-in and update-in. While I realize this is not a bug it is odd and in my eyes unexpected and unwanted behavior.

      get-in called with an empty path returns the hashmap it was given to walk through - this is as I expect and makes a lot of sense when dynamically (with generated pathes ) walking a hash map.

      update-in behaves differently and while from the implementation side, it's behavior too makes sense, it does not work as expected (at least not for me) update-in with an empty map creates a new key 'nil' so:


      {...} [] f) ist he same as (update-in {...}

      [nil] f) while (get-in

      {...} []) is not the same as (get-in {...}

      [nil]) and of cause differs from what update-in does.

      For automatically walking trees the behavior of get-in makes a lot more sense since the current behavior of update-in forces you to check for empty paths and if they are empty fall back to plain assoc and get (or get-in since this works):

      (if-let [r (butlast @path)]
        (alter m update-in r dissoc (last @path))
        (alter m update-in r assoc {:name @sr} c))
        (alter m dissoc (last @path))
        (alter m assoc {:name @sr} c)))

      Next argument is that update-in with an empty map working on nil isn't easy to gasp, one needs to know the implementation details to realize that it works, I think 90% of the people reading update-in with [] will not instinctively know that it works on the key nil, so changing this would most likely not break any current code, and if it would the code would be bad anyway .

      Chouser has, a very nice solution on the mailing list that would fix the problem I'm not sure if I'm entitled to post it here since I did not wrote it but it can be found in this thread:





            • Assignee:
              alex+import import
            • Votes:
              5 Vote for this issue
              7 Start watching this issue


              • Created: