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

Spec tool. A tool for leveraging registered functions specs. #110

Open
jpmonettas opened this issue Nov 20, 2023 · 0 comments
Open

Spec tool. A tool for leveraging registered functions specs. #110

jpmonettas opened this issue Nov 20, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jpmonettas
Copy link
Member

jpmonettas commented Nov 20, 2023

It could be interesting to create a tool that can walk a selected thread timeline and for each FnCall look up the fn-spec registry, and if any, apply it's :args, :fn and :ret spec to the FnCall args and ret, collecting and listing all failures, and allowing the user to quickly jump to failed spots like we do on the Printer.

This should be pretty straight forward to implement. Fn specs can be retrieved with :

(require '[clojure.spec.alpha :as s])

(s/fdef sum
  :args (s/cat :a int? :b int? )
  :ret int?)

(defn sum [a b]
  (+ a b))

(def sum-spec (s/get-spec 'user/sum))

(:args sum-spec)
(:ret sum-spec)

If malli is on the classpath we can also do the same with :

(require '[malli.core :as m])

(m/=> sum [:=> [:cat :int] :int])

;; this can retrieve the schema given the fn ns and name
(get-in (m/function-schemas) '[user sum :schema]) 
@jpmonettas jpmonettas changed the title Spec tool. A tool for leveraging registered function specs. Spec tool. A tool for leveraging registered functions specs. Nov 20, 2023
@jpmonettas jpmonettas added the enhancement New feature or request label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant