Skip to content

Instantly share code, notes, and snippets.

@kornysietsma
Created June 3, 2011 04:07
Show Gist options
  • Save kornysietsma/1005855 to your computer and use it in GitHub Desktop.
Save kornysietsma/1005855 to your computer and use it in GitHub Desktop.
ten clojure one-liners
; 8a
(reduce min [14, 35, -7, 46, 98])
; 8b
(min 14 35 -7 46 98)
; 8c
(apply min [14, 35, -7, 46, 98])
; 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"))))
(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))))
(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")))
(map #(* 2 % ) (range 1 10))
(ns ten
(:require
[clojure.xml]))
(clojure.xml/parse "http://search.twitter.com/search.atom?&q=clojure")
(group-by #(if (> % 60) :passed :failed) [49, 58, 76, 82, 88, 90])
(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)
(reduce + (range 1 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment