-
Notifications
You must be signed in to change notification settings - Fork 218
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
delay/future/promise schemas #1171
base: master
Are you sure you want to change the base?
Conversation
(is (nil? (m/explain [:delay :int] (doto (delay 1) deref)))) | ||
(is (nil? (m/explain [:delay {:force true} :int] (delay 1))))) | ||
(testing "schema does not match delay" | ||
(is (m/validate [:delay :boolean] (delay 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit off: it should fail right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main decision here is whether we should force delays during validation. Given that they often contain blocking code, it might not be the best idea. Here, I thought I'd make the default to only check if realized, and allow the user to tell malli when it's ok to force the delay via a property.
(is (m/explain [:promise :boolean] (doto (promise) (deliver 1)))) | ||
(is (m/explain [:promise {:force true} :boolean] (doto (promise) (deliver 1)))) | ||
(is (m/explain [:promise {:force true} :boolean] (doto (promise) (deliver 1)))) | ||
(is (m/explain [:promise :boolean] 1))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding tests for get-in / walk behaviour, there's been some bugs recently in those
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@@ -2718,6 +2718,66 @@ | |||
:re-transformer (fn [_ children] (apply re/alt-transformer children)) | |||
:re-min-max (fn [_ children] (reduce -re-alt-min-max {:max 0} (-vmap last children)))})}) | |||
|
|||
(defn -deref-schema [{:keys [type]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the naming, but I fear confusion with m/deref
. Not sure what to do about that. Docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original intention for this name was to have an overarching [:deref S]
schema. I couldn't decide whether it should be a simple reify
or a disjunction of :delay
/:promise
/:future
.
I'm not sure if providing a schema called :deref
increases or reduces clarity here.
nice and orthogonal addition to the lib otherwise, love it |
https://clojurians.slack.com/archives/CLDK6MFMK/p1741110236353429