This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-27
Channels
- # beginners (86)
- # calva (1)
- # cider (21)
- # clj-kondo (2)
- # clojure (31)
- # clojure-europe (3)
- # clojure-italy (7)
- # clojure-nl (7)
- # clojure-spec (15)
- # clojure-uk (70)
- # clojurescript (4)
- # clojutre (31)
- # code-reviews (6)
- # cursive (10)
- # datomic (8)
- # duct (3)
- # emacs (2)
- # fulcro (34)
- # funcool (3)
- # jackdaw (2)
- # jobs (10)
- # jvm (2)
- # kaocha (1)
- # off-topic (21)
- # pathom (11)
- # re-frame (10)
- # reagent (4)
- # schema (1)
- # shadow-cljs (72)
- # sql (1)
- # tools-deps (3)
- # vim (9)
- # xtdb (4)
I’m trying to see if I can gain more performance by turning alias-map
transformation into a transducer alias-map-xf
:
(defn alias-map []
(->> emojis
(map (juxt identity :aliases))
(mapcat (fn [[emoji aliases]] (map (fn [alias] [(keyword alias) emoji]) aliases)))
(into {})))
(defn alias-map-xf []
(into {} (comp
(map (juxt :aliases identity))
(mapcat (fn [[aliases emoji]]
(map (fn [alias] [(keyword alias) emoji]) aliases))))
emojis))
emojis
is a vector of emoji
s:
{:emojiChar "string"
:aliases ["alias1" "alias2" ...]
...}
In this example, I want to turn it into:
'(
[:alias1 {:emojiChar "string"
:aliases ["alias1" "alias2" ...]
...}]
[:alias2 {:emojiChar "string"
:aliases ["alias1" "alias2" ...]
...}]
)
Then, put everything in a map.
I did some benchmarks for this: https://github.com/dawran6/emoji/blob/master/dev/user.clj
Do you think the transducer version can be improved?Please let me know if you have any thought: @U09LZR36F @U8MJBRSR5 . Thanks!
that was not the end of the story, go to see the github issue ..
Sorry for the confusion, @U09LZR36F . The xf version is faster than non-xf version now. I should've update the user ns.