Skip to content

Instantly share code, notes, and snippets.

@dazld
Created October 10, 2018 13:32
Show Gist options
  • Select an option

  • Save dazld/95d5cc9978c33c5c0e4f82cbe9170b09 to your computer and use it in GitHub Desktop.

Select an option

Save dazld/95d5cc9978c33c5c0e4f82cbe9170b09 to your computer and use it in GitHub Desktop.
(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