You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure that I would recommend this -- if you really want this validation, another approach would be to wrap the function that's an argument in a schematized function.
That said, we do test equality like this in the tests (just to make sure fns get the right schemas):
you can see that the issue is the argument names are part of the fn-schema (and I don't think there's a way to provide them). They are in there to provide nice documentation of the arglists for tooling, IIRC. I guess technically FnSchema could ignore them when computing equality, but then it couldn't be a Record, and all in all I'm not sure it would be a net win.
That said, if you really want this, you could just write your own `equivalent-fn-schemas
That said, if you really want this, you could just write your own equivalent-fn-schemas function that ignores the arg names and use that in place of =.
This may not be a bug, but I was wondering if => and fn-schema should produce equal records, i.e why aren't they equal in this example:
(require '[schema.core :as s])
(def fn-sig (s/fn-schema (s/fn :- s/Bool [a :- s/Str b :- s/Int])))
(def arrow-sig (s/=> s/Bool s/Str s/Int))
(= fn-sig arrow-sig) ; => false
fn-sig ; => (=> Bool Str Int)
(type fn-sig) ; => schema.core.FnSchema
arrow-sig ; => (=> Bool Str Int)
(type arrow-sig) ; => schema.core.FnSchema
My use case here is that I'm trying to validate the signature of a function parameter and have come up with something like this:
(def ModelWriteFnSchema (s/fn-schema (s/fn :- Doc [app :- App model :- Model doc :- Doc])))
(def ModelWriteFn (s/constrained Function #(= (s/fn-schema %) ModelWriteFnSchema)))
Using => instead of fn-schema seemed more elegant but I couldn't get that to work.
The text was updated successfully, but these errors were encountered: