<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged into</title>
<link>https://ask.clojure.org/index.php/tag/into</link>
<description></description>
<item>
<title>Use transducer arity of `into` in `clojure.walk` namespace</title>
<link>https://ask.clojure.org/index.php/13281/use-transducer-arity-of-into-in-clojure-walk-namespace</link>
<description>&lt;p&gt;It's simple. Just like that:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; clojure.walk/walk:
(outer (reduce (fn [r x] (conj r (inner x))) form form))
=&amp;gt; (outer (into form (map inner) form))
(outer (into (empty form) (map inner form)))
=&amp;gt; (outer (into (empty form) (map inner) form))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; clojure.walk/keywordize-keys:
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)
=&amp;gt; (postwalk (fn [x] (if (map? x) (into {} (map f) x) x)) m)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; clojure.walk/strigify-keys:
(postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)
=&amp;gt; (postwalk (fn [x] (if (map? x) (into {} (map f) x) x)) m)
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13281/use-transducer-arity-of-into-in-clojure-walk-namespace</guid>
<pubDate>Wed, 13 Sep 2023 22:49:05 +0000</pubDate>
</item>
<item>
<title>Is there any performance difference between creating vector via (into [] xs) or (vec xs)?</title>
<link>https://ask.clojure.org/index.php/12996/there-performance-difference-between-creating-vector-into</link>
<description>&lt;p&gt;I can create set/map/vector by two ways:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(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
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(into r xs):&lt;br&gt;
- defines &lt;em&gt;generic&lt;/em&gt; algorithm by conj!-ing input sequence 1 by 1 to passed result collection (uses transient/persistent trick)&lt;/p&gt;
&lt;p&gt;(ctor xs):&lt;br&gt;
- defines precisely type of result data structure&lt;br&gt;
- 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)&lt;/p&gt;
&lt;p&gt;Are there any performance differences between these two ways?&lt;br&gt;
Maybe there is an established idiom what to use when?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12996/there-performance-difference-between-creating-vector-into</guid>
<pubDate>Sat, 03 Jun 2023 11:35:12 +0000</pubDate>
</item>
<item>
<title>Cast to Map$Entry Exception When Trying to (Into {}) After Sequence Operations</title>
<link>https://ask.clojure.org/index.php/11879/cast-mapentry-exception-trying-after-sequence-operations</link>
<description>&lt;p&gt;Is it intended behavior to get this exception  :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class clojure.lang.Keyword cannot be cast to class java.util.Map$Entry
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;on this piece of code :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def a [[&quot;Active&quot; :Transit-RLC &quot;Active&quot;]])

(-&amp;gt;&amp;gt; a
     (transduce
       (comp 
             (map drop-last)
             (map reverse))
       conj [])
     (into {}))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;changing the transducer to &lt;code&gt;(map (-&amp;gt; [(second %) (first %)])&lt;/code&gt; solves the issue.&lt;br&gt;
Thanks&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11879/cast-mapentry-exception-trying-after-sequence-operations</guid>
<pubDate>Sun, 08 May 2022 09:17:12 +0000</pubDate>
</item>
</channel>
</rss>