Fork me on GitHub
#core-async
<
2016-02-22
>
johanatan20:02:37

Hi, suppose i have a vector of channels and I want to get a vector of results from taking one element from each channel. Is this possible? [I'd rather not have to resort to side-effecting doseq but given limitations of core.async mentioned here https://github.com/clojure/core.async/wiki/Go-Block-Best-Practices it may be the only way).

johanatan20:02:46

[That article doesn't mention any workarounds-- only limitations].

johanatan20:02:53

[P.S. this is in ClojureScript]

ghosss20:02:48

Channels are stateful, so taking from channels produces a side effect (the channel changes).

ghosss20:02:11

doseq or no, you can't escape it. unless I'm misunderstanding

johanatan20:02:37

Yes, but doseq will not work for me as I want the entire vector of results and not to accumulate via mutation into an atom the results individually

johanatan20:02:11

In the end, I am swapping the results (as a vector) into an atom and using yet another atom to accumulate the results as they come in seems less than "functional"

johanatan20:02:28

i.e., the point of atoms/swap! is to isolate the mutating parts of your program to the minimal surface area-- if it weren't for the limitation of 'go' here this would be entirely do-able as operations over sets (with a final single swap!)

ghosss20:02:35

you want the ordering the results vector to match the ordering of the vector of channels?

ghadi20:02:38

johanatan: async/into & async/merge

ghadi20:02:47

note order is not preserved with async/merge

johanatan20:02:07

@ghadi: yep, thx! someone also posted that answer in #C03S1L9DN just now