One of the great features of Clojure is that it considers collections as functions which means that it is possible to invoke them
({:a 1, :b 2} :a) => 1
(#{:a :b} :a) => :a
([:a :b :c] 1) => :b
However it would be nice to be able to query the domain and range of those functions independently of their specific type.
The keys
and vals
functions currently implement this but only for Maps. I think it would be a good idea to make those functions more generic by accepting sets and vectors like in the following examples:
(keys #{:a :b}) => (:a :b)
(vals #{:a :b}) => (:a :b)
(keys [:a :b :c]) => (0 1 2)
(vals [:a :b :c]) => (:a :b :c)
The specific use case I have in mind where this feature could be useful is to define a shorter syntax for explicit foreign key mapping in a data oriented DSL for relational data modeling, where #{:attr1 :attr2}
could be used as a shortcut for {:attr1 :attr1, :attr2 :attr2}
.