1
我试图使用棱柱型模式来强制地图(1.0.4)棱镜模式强制 - 重命名映射键
我试图强迫
{:a 1}
到
{:b 1}
使用架构的自定义匹配器:
{:b s/Int}
但这个代码不工作:
(require '[schema.core :as s])
(require '[schema.coerce :as coerce])
((coerce/coercer {:b s/Int}
(fn [s]
(when (= s s/Keyword)
(fn [x]
(if (= x :a)
:b
x)))))
{:a 1})
输出:
#schema.utils.ErrorContainer{:error {:b missing-required-key, :a disallowed-key}}
我试图通过运行在模式相匹配的一切,输出的电流值和模式相匹配下面的代码调试它:
((coerce/coercer {:b s/Int}
(fn [s]
(when true
(fn [x]
(println s x)
x))))
{:a 1})
输出:
{:b Int} {:a 1}
=>
#schema.utils.ErrorContainer{:error {:b missing-required-key, :a disallowed-key}}
看起来好像匹配器一到达地图就炸毁了?