To sort a vector in clojure
(sort [ 2 3 1 4])
returns a list (sorted)
(1 2 3 4)
I can turn it back into the vector by
(into [] (sort [ 2 3 1 4]))
which is kind of inconvenient.
But if I sort a map/dictionary in clojure
(sort {2 "" 3 "" 1 "" 4 ""})
the return
([1 ""] [2 ""] [3 ""] [4 ""])
How do I turn it back into a sorted map? Or is there a better sort function that keeps the type/shape of the input?
emptyandinto, but it turned out to be much less useful than I expected.(apply into ((juxt empty sort) coll)), doesn't seem very useful though.sortdoesn't return a list, but an ArraySeq.(class (sort [2 3 1 4])) ;=> clojure.lang.ArraySeq, vs(class '(4 3 2 1)) ;=> clojure.lang.PersistentList. Clojure has lots of different collection data structures, but there are only a few collection delimiter characters available, so there are things that aren't lists but whose printed representations use parentheses. There are not many functions that return lists, I believe.listis an exception. :-)