This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-26
Channels
- # announcements (10)
- # aws (5)
- # babashka (27)
- # beginners (175)
- # boot (1)
- # braveandtrue (2)
- # calva (11)
- # cider (13)
- # clj-kondo (91)
- # cljs-dev (54)
- # cljsrn (20)
- # clojure (164)
- # clojure-gamedev (3)
- # clojure-uk (43)
- # clojurescript (185)
- # core-async (6)
- # core-typed (1)
- # cursive (1)
- # docker (2)
- # emacs (2)
- # figwheel-main (78)
- # fulcro (69)
- # off-topic (20)
- # pathom (30)
- # planck (3)
- # re-frame (6)
- # reagent (70)
- # reitit (26)
- # ring (1)
- # shadow-cljs (120)
- # tools-deps (6)
- # vim (9)
I didn’t know destructuring could take this form. All the previous forms of desctructuring I’ve seen listed the collection-to-be destructured after the destructuring,
like this: [[first second] collection]
and not just: [[first second]]
I also forgot how reduce uses an accumulator: [accumulator [first second]].
So, if I understand it correctly, In the BraveAndTrue example, {} initializes the accumulator, row-map, and [:name “Edward Cullen”] is the structure-argument that gets destructured by the second pair of parameters, by [vamp-key value]:
[row-map [vamp-key value]]
[{} [:name "Edward Cullen"]]
Seeing the actual arguments consumed by the sequence of function calls helps:
; (mapify ["Edward Cullen" "10"] ["Bella Swan" "0"]...)
; (map fn ["Edward Cullen" "10"] ["Bella Swan" "0"]...)
; (fn ["Edward Cullen" "10"])
; (reduce fn {} (map vector [:name :glitter-index] ["Edward Cullen" "10"]))
; (reduce fn {} [:name "Edward Cullen"] [:glitter-index "10"])
; (fn {} :name "Edward Cullen")
; (assoc {} :name "Edward Cullen")