Created
November 23, 2020 00:15
-
-
Save drewverlee/744463a9855bf436ccf042a9cd4eb8af to your computer and use it in GitHub Desktop.
monads explained via clojure spec.
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
(def my-inc inc) | |
(def my-dec dec) | |
(s/fdef my-inc | |
:args (s/cat :x int?) | |
:fn #(= (inc (-> % :args :x )) | |
(-> % :ret)) | |
:ret int?) | |
(s/fdef my-dec | |
:args (s/cat :x int?) | |
:fn #(= (dec (-> % :args :x )) | |
(-> % :ret)) | |
:ret int?) | |
(s/fdef monoid | |
:args (and | |
(s/cat :some-fn my-inc :some-other-fn my-dec) | |
(= (s/args my-inc) (s/args my-dec)) | |
(= (s/ret my-inc) (s/ret my-dec))) | |
:ret (s/comp my-inc my-dec)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i meant monad in the fdef!