Skip to content

Instantly share code, notes, and snippets.

@juskrey
Forked from Chouser/array_type.clj
Created April 5, 2020 09:53
Show Gist options
  • Save juskrey/3807753194c2b0385c1a648a30c61456 to your computer and use it in GitHub Desktop.
Save juskrey/3807753194c2b0385c1a648a30c61456 to your computer and use it in GitHub Desktop.
Clojure array type hint
(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