specter

Latest version: 1.1.3
nathanmarz 2018-01-09T00:32:13.000340Z

@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)

nathanmarz 2018-01-09T00:32:32.000052Z

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

2018-01-09T00:53:51.000151Z

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.

nathanmarz 2018-01-09T00:55:10.000046Z

@aaelony select, transform etc. implicitly use that macro

nathanmarz 2018-01-09T00:55:38.000021Z

path is the heart of what makes specter work

2018-01-09T01:00:06.000106Z

any reason why path instead of select in this case?

nathanmarz 2018-01-09T01:02:11.000032Z

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

nathanmarz 2018-01-09T01:02:28.000186Z

select invokes a navigator on a piece of data

2018-01-09T02:44:34.000280Z

got it. thanks again