Fork me on GitHub
#code-reviews
<
2015-07-02
>
sveri14:07:40

Hi, I just hacked something together to find out if any string from a file given a list of strings, is contained in any .java file in a folder: https://gist.github.com/sveri/701aa9f1cd1af12a37d7 As much as this solution works, as much I don't like it. Any other ideas on how to approach that? PS: an example is in the bottom of the gist

rwtnorton15:07:44

@sveri, line 15 could take advantage of the alias io. I was expecting to see another re-matches for search-string-in-file. I am wondering if the shape of search-package-in-source could use (--> ... ) leading up to a filter at the end. Clean and easy to read.

crisptrutski15:07:55

@sveri #(= nil %) could just be nil?, but even better (remove #(= nil %) (map #(search-string-in-file % file) libs))) to (remove #(search-string-in-file % file) libs)..

crisptrutski15:07:02

and (if (and needle haystack (.contains (.toLowerCase haystack) (.toLowerCase needle))) fp nil) could be replaced just with that condition, just need a truthy return

crisptrutski15:07:05

and the (reduce (fn [a b] (conj a b)) [] ...)) patterns could be (into [] …) i believe

crisptrutski15:07:08

search-string-in-file is also slurping the file for each search term, might want to memoize or capture that in a closure (curry search-string-in-file to take the file first, this also lets #(search-string-in-file % file) get unwrapped to (search-string-in-file file)