Last active
August 29, 2015 14:05
-
-
Save shaunr0b/40cd8050585c7595e9e0 to your computer and use it in GitHub Desktop.
Firehose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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