Thomas is absolutely right, Philippe.
Things also get easier if you avoid, or defer side effects, and first focus
on pure functions.
So, for example at the REPL, you might first try processing a literal
sequence of lines, repeatedly adjusting the processing code, tweaking the
regex, until you get it right:
(mapv #(re-find #"\w+\.\w+" %) ["abc def.g" "apple.com ibm.com foo"])
;=> ["apple.com" "ibm.com"]
You could turn the above into a pure function that works on a sequence of
lines:
(defn lines->urls [lines] (mapv #(re-find #"\w+\.\w+" %) lines))
You could then define your file reading code in terms of that pure function:
(defn readf [file]
(with-open [r (clojure.java.io/reader file)]
(lines->urls (line-seq r))))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.