Fork me on GitHub
#specter
<
2018-01-01
>
mbjarland20:01:15

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 exapmle

mbjarland20:01:02

I suspect I’m just not friendly enough with transducers and am tripping over myself here

mbjarland20:01:41

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

nathanmarz20:01:20

@mbjarland this works: (reduce + (traverse [ALL :delim ALL string? (view count)] data))

nathanmarz20:01:49

using view lets you avoid needing transducers to make this efficient