Fork me on GitHub
#beginners
<
2017-11-19
>
Andrei Zah07:11:03

hello everyone, I have a quick question about transducers & async channels. why is it that this works:

clojure
(map parse-comment (map :data data))
but this does not:
clojure
(def xf
  (comp
    (map :data)
    (map parse-comment)))
when I use it with an async channel? ->> and transduce both work, it's just when I use it with a chan I start to get nil data. demo code available here: https://hastebin.com/ewuxeyihul.lisp

boldaslove15608:11:43

@zah #(subvec data 0) actually does nothing, it works like identity and with the given xf , your channel expects a map

boldaslove15608:11:41

Think of channel as a vector

Andrei Zah08:11:17

@boldaslove156 sorry I forgot to change the subvec. My real code gets a json response -> converts the stream. (using this lib) https://github.com/dakrone/cheshire

boldaslove15608:11:55

I think you could still get a vector

boldaslove15608:11:19

Check whether you did (put! ch [{:data {...}}]) or (put! ch {:data {...}})

Andrei Zah10:11:32

ah it's [{:data {} }]

Andrei Zah12:11:35

@boldaslove156 is using the vector not possible? the input is [ {:data {}}, {:data {}} ] so into doesn't work as they all get mapped to the same key. here is demo code with real input: https://hastebin.com/vunohahovu.lisp