clojure - Clojure 中的线程注释

标签 clojure functional-programming tree

我希望能够在树数据结构中进行插入(就像在 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/

相关文章:

clojure - 在 Clojure 中找出一个集合是否包含具有给定键值的映射的最简单方法是什么?

clojure - cljc 宏中的错误处理

clojure - 如何从文件中一次读取一行文本,并将文本分配给 Clojure 中的变量

clojure - Clojure 中 definterface 和 defprotocol 的区别

class - 弗雷格类(class)如何运作?

functional-programming - 函数式语言如何模拟副作用?

javascript - zipAll 函数(例如 lodash/fp)的流类型是什么?

algorithm - 将二叉树的前序列表转换为后序列表,反之亦然

haskell - 使用 State Monad 插入树

algorithm - 给定一棵树,找到以特定节点为根的子树中两个值的乘积,使得该乘积具有最少数量的零?