Skip to content

Commit

Permalink
simple parser
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jan 13, 2025
1 parent 88ddc2e commit 602a209
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@
;; Schemas
;;

(defn -simple-parser [this]
(let [valid? (-validator this)]
(fn [x] (if (valid? x) x ::invalid))))

(defn -simple-schema [props]
(let [{:keys [type type-properties pred property-pred min max from-ast to-ast compile]
:or {min 0, max 0, from-ast -from-value-ast, to-ast -to-type-ast}} props]
Expand Down Expand Up @@ -739,9 +743,7 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc))))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-parser [this] (-simple-parser this))
(-unparser [this] (-parser this))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
Expand Down Expand Up @@ -1708,9 +1710,7 @@
(conj acc (miu/-error path in this x (:type (ex-data e))))))))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
(-parser [this]
(let [valid? (-validator this)]
(fn [x] (if (valid? x) x ::invalid))))
(-parser [this] (-simple-parser this))
(-unparser [this] (-parser this))
(-walk [this walker path options] (-walk-leaf this walker path options))
(-properties [_] properties)
Expand Down Expand Up @@ -1753,9 +1753,7 @@
acc)
(catch #?(:clj Exception, :cljs js/Error) e
(conj acc (miu/-error path in this x (:type (ex-data e))))))))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-parser [this] (-simple-parser this))
(-unparser [this] (-parser this))
(-transformer [this transformer method options]
(-intercepting (-value-transformer transformer this method options)))
Expand Down Expand Up @@ -2100,9 +2098,7 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc)))))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-parser [this] (-simple-parser this))
(-unparser [this] (-parser this))
(-transformer [_ _ _ _])
(-walk [this walker path options] (-walk-indexed this walker path options))
Expand Down Expand Up @@ -2182,9 +2178,7 @@
(let [validator (-validator this)]
(fn explain [x in acc]
(if-not (validator x) (conj acc (miu/-error path in this x)) acc)))))
(-parser [this]
(let [validator (-validator this)]
(fn [x] (if (validator x) x ::invalid))))
(-parser [this] (-simple-parser this))
(-unparser [this] (-parser this))
(-transformer [_ _ _ _])
(-walk [this walker path options] (-walk-indexed this walker path options))
Expand Down

0 comments on commit 602a209

Please sign in to comment.