Created
March 9, 2012 19:38
-
-
Save pedroteixeira/2008267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
I've been using google collection/lambdaj/totallylazy/lazyrecords in
the java situation to help too
…On Fri, Mar 9, 2012 at 5:08 PM, Pedro Henriques dos Santos Teixeira ***@***.*** wrote:
for sure, the Java version can be a lot better.
but C#'s LINQ is the best _for now_ https://gist.github.com/2007893 :)
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2008267
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for sure, the Java version can be a lot better.
but C#'s LINQ is the best for now https://gist.github.com/2007893 :)