Skip to content

Instantly share code, notes, and snippets.

@djhworld
Created September 21, 2011 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djhworld/1231651 to your computer and use it in GitHub Desktop.
Save djhworld/1231651 to your computer and use it in GitHub Desktop.
clojure one liners
; double everything in a list
(map #(* 2 %) (range 1 10))
; sum a list of numbers
(reduce + (range 1 1000))
; read a file
(clojure.string/split (slurp "cl.clj") #"\n")
;partition a list
(partition-by #(> % 60) [49, 58, 76, 82, 88, 90])
;find the maximum
((fn [xs] (last (sort xs))) [14 35 -7 98 46])
;find the minimum
((fn [xs] (first (sort xs))) [14 35 -7 98 46])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment