This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-01
Channels
- # beginners (2)
- # cider (20)
- # cljsjs (3)
- # clojure (86)
- # clojure-italy (2)
- # clojure-spec (7)
- # clojure-uk (3)
- # clojurescript (8)
- # defnpodcast (3)
- # emacs (10)
- # figwheel (1)
- # hoplon (9)
- # immutant (4)
- # keechma (2)
- # luminus (11)
- # off-topic (13)
- # re-frame (6)
- # reagent (3)
- # ring (1)
- # specter (5)
- # sql (2)
- # unrepl (127)
how would I go about calculating the sum of the string lengths in the following data structure (oh and yes, Nathan, I did cave in and pull in specter into my project, the convenience is just too alluring):
[{:delim ["-"]} {:align :L} {:delim ["-" :F "-"]} {:align :R} {:delim ["-"]}]
I’m assuming using:
(specter/traverse-all [ALL :delim ALL string?])
together with transduce would somehow do the trick?
the answer from the above data structure should be 4
as there are 4 strings of length 1 in the :delim
maps in the exapmleI suspect I’m just not friendly enough with transducers and am tripping over myself here
one way would be to step out from specter and do:
(reduce +
(map count
(specter/select [ALL :delim ALL string?] my-d)))
but I figured there might be some way of being even terser here@mbjarland this works: (reduce + (traverse [ALL :delim ALL string? (view count)] data))
using view
lets you avoid needing transducers to make this efficient