Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Last active April 18, 2020 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lagenorhynque/3b1f15000053e4eacbd717099b38d976 to your computer and use it in GitHub Desktop.
Save lagenorhynque/3b1f15000053e4eacbd717099b38d976 to your computer and use it in GitHub Desktop.
Speccing a higher-order function with clojure.spec (+ test.check)
dev> (require '[clojure.spec.alpha :as s]
'[clojure.spec.test.alpha :as stest])
nil
dev> (defn twice [f x]
(f (f x)))
#'dev/twice
dev> (s/fdef twice
:args (s/cat :f (s/fspec :args (s/tuple integer?)
:ret integer?)
:x integer?)
:ret integer?)
dev/twice
dev> (stest/instrument `twice)
[dev/twice]
dev> (twice (comp inc #(doto % prn)) 0)
0
0
1
0
-2
7
14
0
-19
-25
-2
99
-7
503
-62
-25
-29
-867
129
-46
-1
0
1
2
@lagenorhynque
Copy link
Author

lagenorhynque commented Apr 18, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment