Skip to content

Instantly share code, notes, and snippets.

@niwinz
Forked from Chouser/array_type.clj
Created July 10, 2019 08:04
Show Gist options
  • Save niwinz/f973511a844fbf791bb34af3e887361a to your computer and use it in GitHub Desktop.
Save niwinz/f973511a844fbf791bb34af3e887361a 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