This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-17
Channels
- # beginners (45)
- # boot (33)
- # chestnut (9)
- # cider (2)
- # cljs-dev (24)
- # cljsrn (1)
- # clojure (114)
- # clojure-conj (3)
- # clojure-dev (3)
- # clojure-dusseldorf (3)
- # clojure-greece (5)
- # clojure-italy (22)
- # clojure-russia (10)
- # clojure-spec (12)
- # clojure-uk (19)
- # clojurescript (117)
- # core-async (16)
- # cursive (3)
- # data-science (1)
- # datomic (5)
- # docs (13)
- # emacs (1)
- # fulcro (13)
- # graphql (1)
- # hoplon (20)
- # immutant (3)
- # jobs (1)
- # juxt (12)
- # lein-figwheel (1)
- # luminus (4)
- # off-topic (12)
- # onyx (61)
- # portkey (1)
- # re-frame (21)
- # reagent (26)
- # ring-swagger (38)
- # rum (1)
- # shadow-cljs (222)
- # slack-help (4)
- # spacemacs (11)
- # specter (67)
- # uncomplicate (236)
Inspired by the youtube video above, I'm trying to re-write some sections of our code to use less go
blocks and <! / >!
if possible. I have a section of code that I'm currently trying to see if I can re-write to use transducers, but am not quite seeing how to do it:
;; get-recipes returns hash-map of ids to values
;; desired return is a (channel containing) an ordered sequence of these values based off the input order of `ids`
(go (let [fetched-recipes (<! (get-recipes ids opts))]
(mapv fetched-recipes ids)))
anyone have any suggestions?
ids is a function, right?
anyway, you may want to pass transducing function as argument, and apply it to the channel on the get-recipes
ids
is not a function; it's simply a vector of strings
is get-recipes
returning a channel of results, or a promise-chan with a single result ?
a channel with a single result (which looks like {"id1" val1 "id2" val2}
)
you can do this with transducers. In general a go that takes from another channel and returns a value can be replaced with a map @tanzoniteblack
`(chan 10 (map (fn [fetched-recipes] (mapv fetched-recipes ids)))`
And then have get-recipes put values on that channel
But at this point I start to wonder why it needs to return a vector of recipies instead of a channel of recipes
Having it return a channel of recipes would be cleaner, I was just trying to minimize the amount of refactoring for my first pass
fair enough
Thanks a lot though, that is...really obvious now that I look at it 🙂
it takes practice 🙂