Created
June 3, 2011 04:07
-
-
Save kornysietsma/1005855 to your computer and use it in GitHub Desktop.
ten clojure one-liners
This file contains hidden or 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
; 8a | |
(reduce min [14, 35, -7, 46, 98]) | |
; 8b | |
(min 14 35 -7 46 98) | |
; 8c | |
(apply min [14, 35, -7, 46, 98]) |
This file contains hidden or 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
; 5a | |
(map #(str "Happy Birthday " (if (= % 3) "dear NAME" "to You")) (range 1 4)) | |
; 5b | |
(for [x (range 1 5)] (println (str "Happy Birthday " (if (= x 3) "dear NAME" "to You")))) | |
; 5c | |
(doseq [x (range 1 5)] (println (str "Happy Birthday " (if (= x 3) "dear NAME" "to You")))) |
This file contains hidden or 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
(ns ten | |
(:require | |
[clojure.java.io :as io])) | |
; 4a | |
(slurp "data.txt") | |
; 4b | |
(take 3 (line-seq (io/reader "data.txt"))) | |
; 4c | |
(with-open [rdr (io/reader "http://oldweb.cecm.sfu.ca/projects/ISC/dataB/isc/C/pi10000.txt")] (take 3 (line-seq rdr))) | |
; 4d | |
(with-open [rdr (io/reader "http://oldweb.cecm.sfu.ca/projects/ISC/dataB/isc/C/pi10000.txt")] (doall (take 3 (line-seq rdr)))) |
This file contains hidden or 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
(ns ten | |
(:require | |
[clojure.java.io :as io])) | |
(pmap #(count %) (line-seq (io/reader "http://oldweb.cecm.sfu.ca/projects/ISC/dataB/isc/C/pi10000.txt"))) |
This file contains hidden or 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
(map #(* 2 % ) (range 1 10)) |
This file contains hidden or 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
(ns ten | |
(:require | |
[clojure.xml])) | |
(clojure.xml/parse "http://search.twitter.com/search.atom?&q=clojure") |
This file contains hidden or 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
(group-by #(if (> % 60) :passed :failed) [49, 58, 76, 82, 88, 90]) |
This file contains hidden or 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
(def words ["clojure", "stm", "compojure", "leiningen", "clojure.core"]) | |
(def tweet "This is an example tweet talking about clojure and leiningen.") | |
; 3a | |
(reduce #(or %1 (.contains tweet %2)) false words) | |
; 3b | |
(some #(.contains tweet %) words) |
This file contains hidden or 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
(reduce + (range 1 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment