Fork me on GitHub
#core-async
<
2020-03-06
>
wombawomba08:03:54

So I’m calling a library that gives me a core.async channel. I want to (lazily) map a function over this channel before returning it to the calling code. How can I make this happen?

wombawomba09:03:00

I’d use core.async/map, but it seems to be eager (e.g. (def ch (a/map inc [(a/to-chan (range 1000000000))])) seems to hang)

fmjrey12:03:30

Though I'm not sure why a/map is not working for you

fmjrey12:03:19

(def ch (a/map (fn [x] (println x) (inc x)) [(a/to-chan (range 1000000000))]))
=> #'user/ch
0

(a/<!! ch)
=> 1
1

wombawomba12:03:14

Okay so I looked into this a bit closer. I’m also confused as to why map is hanging, since it’s definitely not eager (I verified this by mapping a function that prints a message). The same goes for pipeline. Either way, I decided to stick to map; hopefully it won’t hang in more realistic scenarios 🙂 Thanks @fmjrey

noisesmith16:03:39

@wombawomba above, isn't a/to-chan going to hang? map's laziness doesn't come into play

noisesmith16:03:45

that's not the issue, never mind