So I've written a transducer to build up urls from relative links:

  (defn build-url
    ([root]
      (fn [xf]
          (fn 
            ([] (xf))
            ([links] (xf links))
            ([links suffix]
            (xf links (let [root (if (.endsWith root ".html")
                                     (string/replace root #"\w+\.html$" "")
                                     root)]
                            (str root suffix))))))))

This works great when I know the "root" in advance. The issue is that I 
want to run this recursively, building up the links as I go. As an example:
1) The main index page is, e.g., "http://www.website.com/index.html";. The 
"index.html" part gets stripped off by the transducer, leaving the root as 
"http://www.website.com/index.html";.
2) index.html contains, inter alia, a list of links to other index pages, 
e.g. "/index1/", "/index2/", etc.
3) Running the transducer once yields `["http://www.website.com/index1/";, 
"http://www.website.com/index2/"...]`
4) I want to be able to then run the transducer again on the links scraped 
from each of the sub-indexes, ensuring that each is compounded with the 
correct root element, e.g. `["http://www.website.com/index1/foo";, 
"http://www.website.com/index1/bar";, "http://www.website.com/index2/baz";, 
"http://www.website.com/index2/quux"...]`

Ideally, I'd like to be able to do this with as little intermediate "stuff" 
as possible, i.e., not doing something like `(into [] (comp transducer1 
transducer2 build-url) (into [] (comp transducer3 build-url)))`.

Is there a way to capture this with transducers? Something like (fn [foo] 
(mapcat #(somefn foo %) (someotherfn foo))?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to