(ns de.clojure-buch.lazy-reddit-rss) (use 'clojure.contrib.lazy-xml) (defn- match-key-val [m k v] (= (m k) v)) (defn- match-start-k [m k] (and (match-key-val m :type :start-element) (match-key-val m :name k))) (defn- skip-to-title [s] (loop [s s] (if (match-start-k (first s) :item) s (recur (next s))))) (defn- filter-els [e] (or (match-key-val e :type :characters) (or (match-start-k e :title) (match-start-k e :link)))) (defn- filter-groups [s] (and (match-key-val (first s) :name :title) (match-key-val (first (nnext s)) :name :link))) (defn parse-rss [src] (map (fn [s] [((nth s 1) :str) ((nth s 3) :str)]) (filter filter-groups (partition 4 1 (filter filter-els (skip-to-title (parse-seq src)))))))