(defn curry [init depth] | |
(let [mcurry (fn [xs] (fn [x] (conj xs x))) | |
mbind (fn [f1 f2] (fn [xs] (fn [x] (f2 ((f1 xs) x))))) | |
mcurryable (reduce (fn [a _] (mbind mcurry a)) | |
mcurry | |
(into [] (replicate (- depth 1) nil)))] | |
(if (= depth 0) init (mcurryable init)))) | |
(t/deftest curry-test | |
(t/is (= ["meow-0"] (curry ["meow-0"] 0))) | |
(t/is (= ["meow-1" 1] ((curry ["meow-1"] 1) 1))) | |
(t/is (= ["meow-2" 1 2] (((curry ["meow-2"] 2) 1) 2))) | |
(t/is (= ["meow-4" 1 2 3 4] (((((curry ["meow-4"] 4) 1) 2) 3) 4)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment