Skip to content

Instantly share code, notes, and snippets.

@oehme
Created December 21, 2011 18:44
Show Gist options
  • Save oehme/1507155 to your computer and use it in GitHub Desktop.
Save oehme/1507155 to your computer and use it in GitHub Desktop.
Arrays in Clojure, as non-functional as it gets ;)
(defn foo [x]
(cond
(instance? Integer x) "Integer"
(instance? String x) "String"
(instance? Boolean x) "Boolean"))
(defn array-foo [n]
(let [items (object-array ["foo" 23 true]) result (object-array (* 3 n))]
(dotimes [i n]
(dotimes [j 3]
(aset result i
(foo (aget items j)))))
result))
(time (prn (count (array-foo 10000000))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment