I do not think we will extend into to support array sources.

If your source is a vector, then vector seqs are actually really fast and 
into-array is probably not as bad as you think, however it won't apply the 
xf.

into is just doing transduce internally though and transducers are agnostic 
to how their outputs are handled. You could replace the reducing function 
in that transduce with something that incremented the index and set the 
next value like: 

(defn into-long-array [xf v]
  (let [arr (long-array (count v))
        index (volatile! 0)
        conj-arr (fn [a item] 
                   (aset a @index item) 
                   (vswap! index inc) a)]
    (transduce xf (completing conj-arr) arr v)))

(into-long-array (map inc) [0 1 2 3])  ;; returns long[] of [1 2 3 4]

That could be generalized probably to take the array and the index to start 
adding elements, although given expanding transducers like mapcat, this 
would fail so you need some a priori knowledge about that.


On Wednesday, May 11, 2016 at 4:31:02 AM UTC-5, Laszlo wrote:
>
> Hi,
>
>
> The other day I was trying to do an
>
> (into (long-array 0) xform some-vec)
>
> which doesn't work, then I realized there is *into-array* for that, 
> however, it turns everything into a *seq* first.
>
> Is there any plans for extending *into* to hand primitive array, or 
> rewriting *into-array* to do away with the extra allocation?
>
> Thanks,
>
> Laszlo
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to