I can create set/map/vector by two ways:
(into #{} xs) ;; creates PersistentHashSet
(set xs) ;; creates PersistentHashSet
(into {} xs) ;; creates PersistentArrayMap or PersistentHashMap (depends on xs size)
(apply hash-map xs) ;; creates PersistentHashMap
(into [] xs) ;; creates PersistentVector
(vec xs) ;; creates PersistentVector
(into r xs):
- defines generic algorithm by conj!-ing input sequence 1 by 1 to passed result collection (uses transient/persistent trick)
(ctor xs):
- defines precisely type of result data structure
- passes xs sequence as an argument to constructor (which is static java function) so every ctor may define its own logic of creation (maybe by not conj-ing input sequence 1 by 1)
Are there any performance differences between these two ways?
Maybe there is an established idiom what to use when?
Thanks!