File tree 2 files changed +10
-13
lines changed
2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 127
127
128
128
(defn gen-coerce-merge
129
129
[[_ & spec-forms]]
130
- (fn [x opts]
130
+ (fn [x { :as opts :keys [closed]} ]
131
131
(if (map? x)
132
- (reduce (fn [m spec-form]
133
- ; ; for every spec-form coerce to new value;
134
- ; ; we need to compare key by key what changed so that
135
- ; ; defaults do not overwrite coerced values
136
- (into m
137
- (keep (fn [[spec v]]
138
- ; ; new-val doesn't match default, keep it
139
- (when-not (= (get x spec) v)
140
- [spec v])))
141
- (coerce spec-form x (assoc opts :closed true ))))
142
- x
143
- spec-forms)
132
+ (into {}
133
+ (map (fn [spec-form]
134
+ (coerce spec-form x (assoc opts :closed closed))))
135
+ spec-forms)
144
136
:exoscale.coax/invalid )))
145
137
146
138
(defn gen-coerce-nilable
Original file line number Diff line number Diff line change 420
420
(sc/coerce ::merge2 {::foo " 1" :foo " 1" :bar " 1" :c {:a 2 }}))
421
421
" Leave out ok vals" )
422
422
423
+ (is (= {::foo 1 :bar " 1" :foo 1 }
424
+ (sc/coerce ::merge2 {::foo " 1" :foo " 1" :bar " 1" :c {:a 2 }}
425
+ {:closed true }))
426
+ " Remove extras" )
427
+
423
428
(is (= " garbage" (sc/coerce ::merge " garbage" ))
424
429
" garbage is passthrough" )
425
430
You can’t perform that action at this time.
0 commit comments