Fork me on GitHub
#clojure
<
2024-06-23
>
jasonjckn06:06:59

What would be the canonical way to write (->> stream (map side-effect!) dorun), in modern clojure without lazy seqs (i.e. via transducer, reducer, etc), (ignoring doseq, loop, etc). Also bonus question, what about pmap ?

Ben Sless06:06:57

With transducers run! an Eduction or use into

Ben Sless06:06:09

For pmap lemme do a quick search I remember seeing something

jasonjckn06:06:18

didn't know about run! thank you

Ben Sless06:06:16

For parallelism you can slap a core.async pipeline on it, there are a few other things you can do manually, like using an executor service with a fixed size thread pool

👍 1
jasonjckn06:06:38

was just gonna say... pmap, would be i think either via pipelining with core async, or maybe reducers could do it via fold... but you'd be doing IO on the fork join pool which I think is frowned upon.

p-himik06:06:54

Just in case - that particular form can be written as (mapv ... steam).

jasonjckn06:06:29

Sure, yah, to nit pick though, 'dorun` doesn't materialize a collection of the results, whereas mapv does.

p-himik06:06:55

What do you mean? It's literally what dorun is for.

jasonjckn06:06:10

My original question is what's the modern clojure way of accomplishing what dorun does, so mapv while it's modern clojure... since it's transducers underneath, it's not analogous to dorun

p-himik06:06:11

Ah, sorry - I mixed up dorun and doall.

👍 1