Skip to content

Instantly share code, notes, and snippets.

@pedroteixeira
Created March 9, 2012 19:38
Show Gist options
  • Save pedroteixeira/2008267 to your computer and use it in GitHub Desktop.
Save pedroteixeira/2008267 to your computer and use it in GitHub Desktop.
;; http://pragprog.com/magazines/2012-03/comparing-java-and-scalas-expressiveness
;; first attempt for impl in clojure.. a lot to be improved! :)
(let [lines (map #(clojure.string/split % #" ")
(line-seq (clojure.java.io/reader (clojure.java.io/file "textfile.txt"))))
grouped (group-by #(second %) lines)
parse-long (fn [log] (Long/parseLong (first log)))
diff-times (fn [longs] (for [x (range (count longs)) :let [ts (nth longs x)] ]
(if (= 0 x) ts
(- ts (nth longs (- x 1))))))
times (map (comp diff-times #(map parse-long %)) (vals grouped))]
(print (zipmap (keys grouped) times)))
@pedroteixeira
Copy link
Author

for sure, the Java version can be a lot better.
but C#'s LINQ is the best for now https://gist.github.com/2007893 :)

@guilhermesilveira
Copy link

guilhermesilveira commented Mar 9, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment