Created
October 10, 2018 13:32
-
-
Save dazld/95d5cc9978c33c5c0e4f82cbe9170b09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (deftest middlewares | |
| (testing "chain" | |
| (let [add (fn [f v] | |
| (fn [input] | |
| (+ (f input) v))) | |
| sub (fn [f v] | |
| (fn [input] | |
| (- (f input) v))) | |
| chain (-> identity | |
| (add 1) | |
| (add 42) | |
| (sub 1)) | |
| _ (println (chain 0))])) | |
| (testing "other" | |
| (let [add (fn [v] | |
| (fn [input] | |
| (+ input v))) | |
| sub (fn [v] | |
| (fn [input] | |
| (- input v))) | |
| invoke (fn [chain seed] | |
| (reduce (fn [a f] (f a)) seed chain)) | |
| chain [(add 1) (add 42) (sub 1)] | |
| _ (println (invoke chain 0))]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment