On Jun 11, 2013 8:25 AM, "Meikel Brandmeyer (kotarak)" wrote:
> Or another one:
>
> (defn filter-lines
> [rdr]
> (->> (line-seq rdr)
> (mapcat #(str/split % #"\s+"))
> (filter #(<= 4 (count %) 9))
> (into #{})))
>
> (defn filter-file
> [filename]
> (with-open [rdr (io/reader fi
Or another one:
(defn filter-lines
[rdr]
(->> (line-seq rdr)
(mapcat #(str/split % #"\s+"))
(filter #(<= 4 (count %) 9))
(into #{})))
(defn filter-file
[filename]
(with-open [rdr (io/reader filename)]
(filter-lines rdr)))
Meikel
Am Dienstag, 11. Juni 2013 11:04:14 UTC+2
I haven't seen the use of multiple statements in the for comprehension
here, so perhaps it's nice to elaborate that this exists?
(defn filter-file [filename]
(with-open [rdr (io/reader filename)]
(set
(for [line (line-seq rdr)
word (str/split line #"\s+")
:when (<
The 'reduce' solution is very elegant, but you can simplify it further:
(defn filter-file [filename]
(with-open [rdr (io/reader filename)]
(reduce (fn [words line]
(into words (filter #(<= 4 (count %) 9) (str/split line #"\s+"
#{}
(line-seq rdr
Hey,
I pasted the code into gist ( https://gist.github.com/thheller/5734642 )
and copy&pasted that into the post.
Cheers,
/thomas
On Mon, Jun 10, 2013 at 6:01 PM, Alan Thompson wrote:
> Hey Thomas - How'd you get the nice syntax highlighting in your post?
> Alan
>
>
> On Sat, Jun 8, 2013 at 7:
Hey Thomas - How'd you get the nice syntax highlighting in your post?
Alan
On Sat, Jun 8, 2013 at 7:16 PM, Steven D. Arnold
wrote:
> Thanks for the responses! As suggested, wrapping in 'doall' does work.
>
>
> On Jun 8, 2013, at 3:28 AM, Thomas Heller wrote:
>
> (defn filter-file [filename]
>
Thanks for the responses! As suggested, wrapping in 'doall' does work.
On Jun 8, 2013, at 3:28 AM, Thomas Heller wrote:
> (defn filter-file [filename]
> (with-open [rdr (io/reader filename)]
>(reduce (fn [words line]
> (->> (str/split line #"\s+")
> (filter
Hey,
for produces a lazy sequence (as does flatten) which is hurting you here.
You could wrap everything in a doall but I'd recommend using reduce since
thats technically what you want here. I'd probably go for something like:
(defn filter-file [filename]
(with-open [rdr (io/reader filename)
On Sat, Jun 8, 2013 at 12:53 AM, Steven D. Arnold
wrote:
> (defn filter-file
> []
> (with-open [rdr (reader "/Users/thoth/wordlist.txt")]
>(flatten
> (for
>[line (line-seq rdr)]
>(filter
> (and #(<= (count %) 9)
> #(>= (count %) 4))
> (spl