Skip to content

Instantly share code, notes, and snippets.

@andrewwhitehouse
Created May 12, 2019 11:42
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 andrewwhitehouse/e766bb26d9f79647f4caa6e23ef35fc6 to your computer and use it in GitHub Desktop.
Save andrewwhitehouse/e766bb26d9f79647f4caa6e23ef35fc6 to your computer and use it in GitHub Desktop.
Examples from coaching session at ClojureBridge 11th May
(println "Hello World")
(map inc (range 10))
(def numbers [10 27 26 21 22 22 45 34 59 60])
(/ (apply + 0.0 numbers) (count numbers))
(apply min numbers)
(use 'clojure.repl)
(source range)
(defn- sum [value-quantity-map]
(reduce (fn [acc [value quantity]]
(+ acc (* value quantity)))
0
value-quantity-map))
(+ (* 3 4) (+ 1 2))
(defn add [x y] (+ x y))
(defn add-all [x & args] args)
(add-all 1 2 3)
(defn show-args [args] args)
(show-args [1 2 3])
(doc vec)
(vec '(1 2 3))
(doc vector)
(vector 1 2 3 4 5)
(mapv #(+ %1 1) '(1 2 3))
(mapv (fn [val] (+ val 1)) '(1 2 3))
(source defn)
(defn add3 [x] (+ x 3))
(def add3 (fn [x] (+ x 3)))
(fn [x] body)
'(1 2 3)
(quote (1 2 3))
#(+ % 1)
(repeat 5 10)
(cons 20 (repeat 3 30))
(doc conj)
(cons 1 [2 3 4])
(conj [2 3 4] 1)
(conj '(1 2 3) 1)
(loop [remaining '("one" "two" "three")]
(if-let [element (first remaining)]
(do
(println "element" element)
(recur (rest remaining)))))
(map println ["one" "two" "three"])
(let [x 3]
(println x))
(doc doseq)
(let [[a b] [1 2]]
(str "a=" a " b=" b))
(+ 1 2 3)
(doc contains?)
(some #{"two"} ["one" "two" "three"])
(some #{\3} (map identity "123"))x
(doc some)
(macroexpand-1 '(-> (sort [10 27 26]) (first)))
(apply str [1 2 3])
(source apply)
(apply f [1 2 3])
(f 1 2 3) ; comment
(use 'clojure.test)
;; load your code here
(run-test 'namespace)
((fn [a b c] (+ a b c)) 1 2 3)
(doc sort)
(doc min)
(take 10 (iterate inc 1))
(def people [{:age 25 :name "jim"} {:age 18 :name "abby"}])
(sort-by :name people)
(first nil)
(doc nth)
(doc get)
(> 25 10)
(and true true)
(= "one" (str "o" "ne"))
(< 1 2 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment