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

Phrasing (s/int-in min max) #33

Open
Ramblurr opened this issue Aug 17, 2020 · 1 comment
Open

Phrasing (s/int-in min max) #33

Ramblurr opened this issue Aug 17, 2020 · 1 comment

Comments

@Ramblurr
Copy link

Here is a simple example using spec's int-in

(defphraser :default
  [_ problem]
  problem)

(defphraser (s/int-in min max)
  [_ _ min max]
  (str "must be between " min " and " max))

(s/def ::total-widgets (s/int-in 1 32))

(phrase/phrase-first {} ::total-widgets 100)

This hits the default handler, and the problem map has the pred value

  :pred ( clojure.core/fn [ % ] ( clojure.spec.alpha/int-in-range? 1 32 % ) )

What's the proper way to phrase this?

@Ramblurr
Copy link
Author

It seems this does indeed work, but seems very hacky since it is exposing spec (albeit not very complicated) internals

(defphraser
  (clojure.core/fn [%] (clojure.spec.alpha/int-in-range? min max %))
  [_ _ min max]
  (str "must be between " min " and " max))

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

No branches or pull requests

1 participant