Skip to content

Instantly share code, notes, and snippets.

@shaunr0b
Last active August 29, 2015 14:05
Show Gist options
  • Save shaunr0b/40cd8050585c7595e9e0 to your computer and use it in GitHub Desktop.
Save shaunr0b/40cd8050585c7595e9e0 to your computer and use it in GitHub Desktop.
Firehose
(def box (atom nil))
(def futures (atom nil))
{:a "1" :b "2"}
[:a "1"]
[:b "2"]
(defn my-fn [{input-map :key some-var :a} name [x y z] ]
(let [[f s] input-map]
z))
(my-fn {:a 1 :key [3 4]} "ari" [1 2 3])
(reset! box nil)
(->> [{:a 1 :b 2} {:a 2 :c 1} {:a 1} {:a 5}]
(remove (fn [mp] (get mp :b)))
(reduce (fn [m mp] (+ m (:a mp))) 0))
(->> [{:a 1 :b 2} {:a 2 :c 1} {:a 1} {:a 5}]
(reduce (fn [m mp] (+ m (:a mp))) 0))
(doseq [letter [:a :b :c :d :e]]
(swap! futures conj
(future (Thread/sleep (* 1000 (+ 1 (rand-int 5))))
(reset! box letter))))
(add-watch box :listener (fn [_ _ o n]
(println n)))
(def counter (atom 0))
(swap! counter inc)
(defn my-map [f coll]
(reduce (fn [m k] (conj m (f k)))
[]
coll))
(defn my-filter [f coll]
(reduce (fn [m k] (if (f k)
(conj m k)
m))
[]
coll))
(my-filter even? [1 2 3 4])
(my-map inc [1 2 3 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment