Fork me on GitHub
#specter
<
2018-01-09
>
nathanmarz00:01:13

@aaelony with specter it would be something like:

(defn first-matching-tag [tag]
  (path (filterer #(= (:tag %) tag)) FIRST))

(select
  [(first-matching-tag :html)
   :content
   (first-matching-tag :div)
   :content
   (first-matching-tag :h2)
   ALL
   :content
   FIRST
   (view #(str/split #" "))
   (fn [[verb _]] (#{"GET" "POST" "DELETE" "HEAD"} verb))
   
  ]
 data)

nathanmarz00:01:32

plus a little extra code to do that processing of "inputs" in your code

aaelony00:01:51

Thank-you, @nathanmarz. Looks more elegant and concise. I was unaware of the path macro. I’ll need to look into it. Eager to understand Specter better.

nathanmarz00:01:10

@aaelony select, transform etc. implicitly use that macro

nathanmarz00:01:38

path is the heart of what makes specter work

aaelony01:01:06

any reason why path instead of select in this case?

nathanmarz01:01:11

first-matching-tag returns a navigator to be composed with rest of path

nathanmarz01:01:28

select invokes a navigator on a piece of data

aaelony02:01:34

got it. thanks again