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