The core collection data structures (lists, vectors, maps, and sets) have variadic functions to create them: list
, vector
, hash-map
, hash-set
. 2 of them have 1-arity functions that take in a collection and convert them to the desired concrete collection type: vec
and set
. Maps and lists don't have such a function. I think I understand why maps don't: Hard/impossible to convert between it and other collection types when it requires pairs without a middle step to perform the pairing.
But it seems that there's a missing function that takes in a single object of any collection type and converts it to a concrete PersistentList. Something as simple as (defn to-list [coll] (clojure.lang.PersistentList/create coll))
. Is there a specific reason for its exclusion?
My reasons for asking/desiring such a function are because I am building and then traversing nested data structures, and it can be challenging to correctly handle branches where the output of the various Clojure core functions that operate on "lists" end up returning non-PersistentLists (such as list*
and cons
and syntax quote). I wrote my own to-list
and have been peppering it where necessary to make my decision trees easier after realizing that list*
didn't fit the bill.
I know that the sequence abstraction is a big part of the mindset of Clojure, but list?
not returning true on things I wrote that I know for sure have a bounded size has led to some frustration.
I'm primarily interested in hearing about any reasoning for the deliberate exclusion of such a function but alongside that request, if the core team is interested, I can provide a patch for its addition.