我有这个结构:
[{"a" {"b" 1 "c" 2}
"children" [{"a" {"b" 3 "c" 4} "children" []}]}
{"a" {"b" 5 "c" 6} "children" []}
{"a" {"b" 7 "c" 8}
"children" [{"a" {"b" 9 "c" 10} "children" []} {"a" {"b" 10 "c" 10} "children" []}]}]
我试图编写一个算法来移动矢量中的元素。例如,在最后一个元素中,它具有children
向量:
"children" [{"a" {"b" 9 "c" 10} "children" []} {"a" {"b" 10 "c" 10} "children" []}]
我的函数应该搜索特定的嵌套映射 - 让我们说,找到它的10
属性值为b
的映射。我会找到{"a" {"b" 10 "c" 10} "children" []}
。一旦找到它,我需要用向量改变它的位置。我们假设children
将成为:
"children" [{"a" {"b" 10 "c" 10} "children" []} {"a" {"b" 9 "c" 10} "children" []}]
使用Zipper,我能够遍历并找到嵌套的地图,但不知道如何在矢量中移动它。
以下是我的拉链创建方式:
(z/zipper #(contains? % "children") #(get % "children") (fn [_ c] c) data-structure)