Clojure:将具有关键字键的映射转换为具有等效字符串键的映射

时间:2019-03-11 09:10:10

标签: dictionary clojure

我有一个类似procedure VSTBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); begin if (CellPaintMode = cpmPaint) and (Node = vstStrom.HotNode) then begin TargetCanvas.Brush.Color := clGreen; TargetCanvas.FillRect(CellRect); end; end; 的地图,并且想要将其键转换为字符串,例如{:a "A" :b "B"}

我有此功能,可以正常工作:

{"a" "A" "b" "B"}

但是还有更惯用的或专用的方法吗?

谢谢!

1 个答案:

答案 0 :(得分:8)

有一个内置函数可以将映射键递归转换为字符串:

(clojure.walk/stringify-keys {:a "A" :b "B"})
=> {"a" "A", "b" "B"}
(clojure.walk/stringify-keys {:a "A" :b {:c "C"}})
=> {"a" "A", "b" {"c" "C"}}