Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deref-all in utils? #772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/malli/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,20 @@
([?schema k default]
(get ?schema k default nil))
([?schema k default options]
(let [schema (m/schema (or ?schema :map) options)]
(let [schema (m/deref-all (or ?schema :map) options)]
(when schema (m/-get schema k default)))))

(defn assoc
"Like [[clojure.core/assoc]], but for LensSchemas."
([?schema key value]
(assoc ?schema key value nil))
([?schema key value options]
(m/-set (m/schema ?schema options) key value)))
(m/-set (m/deref-all ?schema options) key value)))

(defn update
"Like [[clojure.core/update]], but for LensSchema instances."
[schema key f & args]
(m/-set (m/schema schema) key (apply f (get schema key) args)))
(m/-set (m/deref-all schema) key (apply f (get schema key) args)))

(defn get-in
"Like [[clojure.core/get-in]], but for LensSchemas."
Expand All @@ -332,7 +332,7 @@
([?schema ks default]
(get-in ?schema ks default nil))
([?schema [k & ks] default options]
(let [schema (m/schema (or ?schema :map) options)]
(let [schema (m/deref-all (or ?schema :map) options)]
(if-not k
schema
(let [sentinel #?(:clj (Object.), :cljs (js-obj))
Expand All @@ -347,7 +347,7 @@
([?schema ks value]
(assoc-in ?schema ks value nil))
([?schema [k & ks] value options]
(let [schema (m/schema ?schema options)]
(let [schema (m/deref-all ?schema options)]
(assoc schema k (if ks (assoc-in (get schema k (m/schema :map (m/options schema))) ks value) value)))))

(defn update-in
Expand Down