我希望能够在树数据结构中进行插入(就像在 Disqus、Hacker News 等上做评论的那个)。以一种巧妙的功能方式来做到这一点会很好。
例子
(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}]}])
问题是如何插入这样的评论
(add-comment cmts :name "Iba" :text "I think so too!" :in-reply-to 1)
以某种简洁/优雅的方式。
或者:解决问题的更简单方法是什么?
最佳答案
如果您希望进行功能树编辑(编辑嵌套数据结构),那么也许
zipper library是正确的工具。
关于clojure - Clojure 中的线程注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9669386/