Skip to content

Instantly share code, notes, and snippets.

@ir4y
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save ir4y/31d19c429226a9bbe7f4 to your computer and use it in GitHub Desktop.

Select an option

Save ir4y/31d19c429226a9bbe7f4 to your computer and use it in GitHub Desktop.
(item 10 nil
(item 20 nil
(item 30 (item 25 nil)
(item 35 nil))))
(+ 1 2) ;; 1 + 2
(def my-fun
(fn [a b c]
(* (+ a b)
c)))
(#(+ 1 %) 1)
(my-fun 4 5 6)
(defn my-fun [a b c]
(let [my-sum (+ a b)
result (* my-sum c)]
(if (odd? result)
"odd"
"not odd")))
(my-fun 2 1 1)
d
(if true
(+ 1 2)
(+ 4 5))
(def my-list '(1 2 3 4 5 6))
(rest '())
(defn get_length [lst]
(if (= lst '())
0
(+ 1 (get_length (rest lst)))))
(get_length my-list)
(+ 1 2)
'(= 1 2)
(get [1 2 3 4 5 7] 1)
(conj [1 2 3] 4)
(get {:one "a" :two "b" :three "c"} :two)
(merge {:foo :bar :one 1} {:one :two})
(assoc {:hello :world :key nil} :key "value")
(dissoc {:hello :world :key nil} :key)
(get #{99 2 3 4} "none")
(:one {:foo :bar})
({:foo :bar} :foo)
(map #(+ 1 %) [ 1 2 3 4])
(filter :id [{:id nil} {:id 1} {:id 2}])
(map {1 "one"
2 "two"
3 "three"}
[1 2 2 3 1])
(remove #(< (get_length %) 2) [[1 2 3] [1] [3 4 5] [1 2] [5 6 7 8]])
(defn bootstrap-todo [id checked text]
{
:checked checked
:id id
:text text})
(bootstrap-todo 1 true "hello")
(defn new-todo [checked text]
(let [id (rand-int 1000)]
(bootstrap-todo id checked text)))
(new-todo true "hello")
(def done-todo (partial new-todo true))
(done-todo "hello")
(def active-todo (partial new-todo false))
(active-todo "world")
(defn done? [todo] (todo :checked))
(def active? (complement done?))
(active?
(done-todo "world"))
(defn get-todo-generator [create-todo]
(fn [& todos]
(into
[]
(for [todo todos]
(create-todo todo)))))
(def active-generator (get-todo-generator active-todo))
(def done-generator (get-todo-generator done-todo))
(active-generator "foo" "Bar" "hello" "wor;d")
(def random-generator
(get-todo-generator
(fn [text] (new-todo (= 0 (rand-int 2)) text))))
(def todo-list-2 (random-generator "foo" "Bar" "hello" "wor;d"))
(def text "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
(def random-todo-texts (clojure.string/split text #"\s"))
(def todo-list-1 (apply random-generator random-todo-texts))
(def todo-database {:user1 todo-list-1 :user2 todo-list-2})
(def active-todo-set (partial filter active?))
(def done-todo-set (partial filter done?))
(def user1-active-todos (comp active-todo-set :user1))
(def user2-done-todos (comp done-todo-set :user2))
(user1-active-todos todo-database)
(user2-done-todos todo-database)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment