Skip to content

Commit

Permalink
move code into correct place in file
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Sep 3, 2023
1 parent 69b44fb commit a433828
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,27 @@
x))))
:cljs (fn [x] (into (when x empty) (map t) x))))

(defn -or-transformer [this transformer child-schemas method options]
(let [this-transformer (-value-transformer transformer this method options)]
(if (seq child-schemas)
(let [transformers (-vmap #(or (-transformer % transformer method options) identity) child-schemas)
validators (-vmap -validator child-schemas)]
(-intercepting this-transformer
(if (= :decode method)
(fn [x]
(key (reduce-kv
(fn [acc i transformer]
(let [x* (transformer (val acc))]
(if ((nth validators i) x*)
(reduced (miu/-tagged x*))
(miu/-tagged (or (key acc) x*) x))))
(miu/-tagged nil x) transformers)))
(fn [x]
(reduce-kv
(fn [x i validator] (if (validator x) (reduced ((nth transformers i) x)) x))
x validators)))))
(-intercepting this-transformer))))

;;
;; ast
;;
Expand Down Expand Up @@ -727,28 +748,6 @@
(-get [_ key default] (get children key default))
(-set [this key value] (-set-assoc-children this key value)))))))

(defn -or-transformer [this transformer child-schemas method options]
(let [this-transformer (-value-transformer transformer this method options)]
(if (seq child-schemas)
(let [transformers (-vmap #(or (-transformer % transformer method options) identity) child-schemas)
validators (-vmap -validator child-schemas)]
(-intercepting this-transformer
(if (= :decode method)
(fn [x]
(key (reduce-kv
(fn [acc i transformer]
(let [x* (transformer (val acc))]
(if ((nth validators i) x*)
(reduced (miu/-tagged x*))
(miu/-tagged (or (key acc) x*) x))))
(miu/-tagged nil x) transformers)))
(fn [x]
(reduce-kv
(fn [x i validator] (if (validator x) (reduced ((nth transformers i) x)) x))
x validators)))))
(-intercepting this-transformer))))


(defn -or-schema []
^{:type ::into-schema}
(reify IntoSchema
Expand Down

0 comments on commit a433828

Please sign in to comment.