Last active
September 20, 2022 17:45
-
-
Save kannangce/932851633902c7f5b398540a7649a294 to your computer and use it in GitHub Desktop.
Handy Clojure utils functions.
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 create-matrix | |
"Creates a multi-dimensional vector with dimensions given in dims | |
with the given default value" | |
([default-value & dims] | |
(loop [val default-value remaining dims] | |
(if (empty? remaining) | |
val | |
(recur (vec (repeat (first remaining) val)) | |
(rest remaining))) | |
)) | |
([] nil)) | |
(defn apply-fn-times | |
"Applies given function f for the given times t on the result of | |
each application, starting with p. | |
For ex (apply-fn-times inc 1 3) is equivalent to (inc(inc(inc 1)))" | |
[f p t] | |
((apply comp (repeat t f)) p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment