What about (run! my-side-effect-fn coll)
This doesn't handle multiple coll at a time like the sequence function, but you can tupleize coll with (map vector coll1 coll2) at some loss of efficiency. Or you can roll your own.
It's not crystal clear to me what you are after, either from this post or the one you link to. I think you want a map that does not produce intermediate collections and accepts multiple colls as input at a time?
Do you have some pseudocode example so we can be precise?
What about (run! my-side-effect-fn coll)
This doesn't handle multiple coll at a time like the sequence function, but you can tupleize coll with (map vector coll1 coll2) at some loss of efficiency. Or you can roll your own.
(def x (vec (range 3)))(def y (vec (reverse x)))(run!
(fn [[x y]] (println x y))
(map vector x y))
> lein run
0 21 12 0
(dotimes [i (count x) ](println (x i) (y i)))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Huh. I was also unaware of the run! function.I suppose you could always write it like this:(def x (vec (range 3)))(def y (vec (reverse x)))(run!(fn [[x y]] (println x y))(map vector x y))> lein run0 21 12 0
although the plain old for loop with dotimes looks simpler:(dotimes [i (count x) ](println (x i) (y i)))maybe that is the best answer? It is hard to beat the flexibility of a a loop and an explicit index.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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+u...@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+unsubscribe@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+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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
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+unsubscribe@googlegroups.com.
(require '[uncomplicate.fluokitten.core :as f])=> nil(def side-effect (constantly nil))=> #'user/side-effect(def col1 (range 10000))=> #'user/col1(def col2 (range 10000))=> #'user/col2(def col2 (vec (range 10000)))=> #'user/col2(def col1 (vec (range 10000)))=> #'user/col1
(time (dotimes [_ 10] (doseq [x col1] (side-effect x))))"Elapsed time: 13.916077 msecs"=> nil(time (dotimes [_ 10] (dorun (map side-effect col1))))"Elapsed time: 5.707441 msecs"=> nil(time (dotimes [_ 10] (run! side-effect col1)))"Elapsed time: 1.190621 msecs"=> nil
(time (dorun (map side-effect col1 col2)))"Elapsed time: 13.194375 msecs"=> nil(time (run! side-effect (map vector col1 col2)))"Elapsed time: 17.54224 msecs"=> nil(time (run! side-effect (mapv vector col1 col2)))"Elapsed time: 3.892984 msecs"=> nil(time (f/foldmap f/op nil side-effect col1 col2))"Elapsed time: 12.454673 msecs"=> nil(time (dorun (sequence (map side-effect) col1 col2)))"Elapsed time: 31.321698 msecs"=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 31.321698 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 15.492247 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 10.9549 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 9.122967 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 18.056823 msecs"
=> nil
(time (dorun (sequence (map side-effect) col1 col2)))
"Elapsed time: 9.381068 msecs"
=> nil
Just a general note of caution. range is a highly specialized (and optimized) impl for both reducing and seq traversal. Also note that seqs on vecs are about the next-most optimized seq (because they also don't allocate or cache - rather they just pull from the vector nodes as the backing store for elements). So just be cautious about making general conclusions about reduce and seq performance from these two specific cases.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/Q5uZcYRdbgg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+unsubscribe@googlegroups.com.
(def v1 (vec (range 10000)))
(def v2 (vec (range 10000)))
(def side-effect (constantly nil))
(defn side-effect-2 [a b] nil)
(with-progress-reporting (quick-bench (foldmap op nil side-effect-2 v1 v2)))
Execution time mean : 290.822794 µs
(with-progress-reporting (quick-bench (run! side-effect (mapv vector v1 v2))))
Execution time mean : 847.292924 µs
(defn side-effect-3 [a] nil)
(with-progress-reporting (quick-bench (run! side-effect-3 (mapv vector v1 v2))))
Execution time mean : 847.554524 µs
(def sv1 (sv v1))
(def sv2 (sv v2))
(defn side-effect-4 ^double [^double a ^double b] 1.0)
(with-progress-reporting (quick-bench (foldmap (double-fn +) 0 side-effect-4 sv1 sv2)))
Execution time mean : 16.436371 µs