Threaded comments in Clojure

I would like to be able to create inserts in the data structure of the tree (for example, someone who makes comments on Disqus, Hacker News, etc.). And it would be nice to do it in a smart functional way.

Example

(def cmts [{:name "Abi" :id 1 :text "Great question" :children nil} {:name "Bib" :id 2 :text "What about zippers?" :children [{:name "Linus" :id 3 :text "I don't understand how to and insert children at a certain id with them" :children nil}]}]) 

The problem is how to insert a comment like this

 (add-comment cmts :name "Iba" :text "I think so too!" :in-reply-to 1) 

in some concise / elegant way.

Or: what would be easier to solve the problem?

+4
source share
2 answers

If you want to perform a functional tree editing (editing neste data structures), then perhaps the zipper library is the right tool.

+3
source

I understand that the clojure.walk library has some very good functionality that can do the trick. http://clojuredocs.org/clojure_core/clojure.walk

0
source

Source: https://habr.com/ru/post/1401003/


All Articles