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

delay/future/promise schemas #1171

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Conversation

frenchy64
Copy link
Collaborator

(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)))
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

@frenchy64 frenchy64 changed the title WIP: Delay schema WIP: delay/future/promise schemas Mar 8, 2025
@frenchy64 frenchy64 changed the title WIP: delay/future/promise schemas delay/future/promise schemas Mar 9, 2025
@frenchy64 frenchy64 marked this pull request as ready for review March 9, 2025 00:30
(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)))))
Copy link
Member

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

Copy link
Collaborator Author

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]}]
Copy link
Member

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?

Copy link
Collaborator Author

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.

@opqdonut
Copy link
Member

nice and orthogonal addition to the lib otherwise, love it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants