Created
August 23, 2018 16:00
-
-
Save mtnygard/a0ff9365ce8c1508adbc1c76160a91ea to your computer and use it in GitHub Desktop.
A clojure.spec.gen.alpha generator that picks a multimethod implementation from the known set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn multimethod-selector | |
"Returns a generator that picks one dispatch value from the known | |
dispatch values of a multimethod. Defers the lookup of dispatch | |
values until sampling time, so any defmethods evaluated after the | |
generator is created may still be selected." | |
[s] | |
#(sgen/bind | |
(sgen/int) | |
(fn [i] | |
(let [ms (keys (methods s))] | |
(sgen/return (nth ms (mod i (count ms)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment