Created
September 22, 2015 14:27
-
-
Save Chouser/a571770f06ef2a9c5334 to your computer and use it in GitHub Desktop.
Clojure array type hint
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 array-type | |
"Return a string representing the type of an array with dims | |
dimentions and an element of type klass. | |
For primitives, use a klass like Integer/TYPE | |
Useful for type hints of the form: ^#=(array-type String) my-str-array" | |
([klass] (array-type klass 1)) | |
([klass dims] | |
(.getName (class | |
(apply make-array | |
(if (symbol? klass) (eval klass) klass) | |
(repeat dims 0)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment