Messy threading

48 views
Skip to first unread message

Oliver George

unread,
May 17, 2013, 12:30:04 AM5/17/13
to enliv...@googlegroups.com
Hello

I'm playing with enlive to scrape some html.  The code I produce feels a oddly messy and I'm wondering if I'm missing some conventions.  (This is a total nitpick.)

The particular issue I see is that (select node css) args are ordered for thread first, but to process the resulting list of elements I want thread last maps.

For example

(def video-links
  (-> list-url URL. html-resource
      (select [:a.lecture-links])
      #(map :attrs %)
      #(map :data-model-iframe %)))

vs 

(def video-links
  (->> list-url URL. html-resource
       #(select % [:a.lecture-links])
       (map :attrs)
       (map :data-model-iframe)))

vs

(def video-links
  (->> (-> url URL. html-resource (select [:a.lecture-links]))
       (map :attrs)
       (map :data-model-iframe)))

vs

(def sel [n c] (select c n)
(def video-links
  (->> (html-resource (URL. list-url))
      (sel [:a.lecture-links])
      (map :attrs)
      (map :data-model-iframe)))
 
Perhaps, in hindsight, the api should have been defined with the args reversed?

cheers, Oliver
Reply all
Reply to author
Forward
0 new messages