This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-03
Channels
- # announcements (5)
- # babashka (8)
- # beginners (98)
- # biff (2)
- # calva (20)
- # cider (16)
- # clerk (2)
- # clj-kondo (20)
- # cljdoc (19)
- # clojure (90)
- # clojure-art (3)
- # clojure-boston (1)
- # clojure-europe (7)
- # clojure-nl (2)
- # clojure-norway (47)
- # clojure-uk (3)
- # clojurescript (10)
- # cursive (10)
- # data-science (1)
- # datalevin (1)
- # defnpodcast (1)
- # events (2)
- # fulcro (11)
- # gratitude (2)
- # honeysql (18)
- # hyperfiddle (11)
- # introduce-yourself (1)
- # jobs (2)
- # lambdaisland (4)
- # lsp (6)
- # malli (4)
- # membrane (3)
- # off-topic (58)
- # polylith (14)
- # portal (2)
- # releases (2)
- # ring-swagger (4)
- # tools-deps (8)
- # xtdb (8)
(>defn with-opts
[x & {:as opts}]
[int? (s/keys*) => nil?]
nil)
(defn with-opts-no-g
[x & {:as opts}]
nil)
(comment
(with-opts 1 1)
; Execution error (IllegalArgumentException) at com.fulcrologic.guardrails.core/run-check (core.cljc:109).
; Don't know how to create ISeq from: java.lang.Long
(with-opts-no-g 1 1))
; nil
Is this a bug in Guardrails 1.2.5?I think a bare s/keys* is valid just like a bare s/keys is so it should work. > Thus a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional. > keys* has the same syntax and semantics as keys but can be embedded inside a sequential regex structure.
(s/conform (s/or :map (s/keys :req [::x])
:opts (s/keys*))
{::x 1})
; [:map #:com.example.playgrounds.spec{:x 1}]
(s/conform (s/or :map (s/keys :req [::x])
:opts (s/keys*))
[::x 1]))
; [:opts #:com.example.playgrounds.spec{:x 1}]
You have a function that says it wants x
. and then wants to make a map out of the remaining varargs…thus, don’t t hose remaining args have to be an EVEN number of them? You’re calling it with a single extra arg, which is odd.
You're right, that is odd, but the behaviour with Guardrails is different than without:
(defn with-opts-no-g
[x & {:as opts}]
opts)
(comment
(with-opts-no-g 1) ; nil
(with-opts-no-g 1 2) ; 2
(with-opts-no-g 1 2 3) ; {2 3}
(with-opts-no-g 1 2 3 4))
; Execution error (IllegalArgumentException) at com.example.playgrounds.spec/with-opts-no-g (REPL:71).
; Don't know how to create ISeq from: java.lang.Long
Not sure if that's worth pursuing as it is misuse in the first place, but the difference between Guardrails and without is something.