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
;; | |
;; When refactoring this kind of stuff, I tend to create functions to transform one of the items | |
;; This way, the threading stuff doesn't get to complicated. | |
;; | |
(defn ->sku-name-type [product] | |
(let [type (:type product)] | |
(->> product | |
:variations | |
(map val) |
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 recipe [{:action :grab | |
:item :sugar} | |
{:action :add-to-bowl} | |
{:action :grab | |
:item :flour} | |
{:action :add-to-bowl} | |
{:action :grab | |
:item :milk} | |
{:action :add-to-bowl} | |
{:action :mix} |
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
(ns barbershop.core | |
(:require [clojure.core.async :refer | |
[dropping-buffer timeout chan go-loop <! chan ]])) | |
(def shop (chan (dropping-buffer 3))) | |
(defn customer [i shop] | |
(put! shop i (fn [v] (println "customer" i "going to the barber")))) | |
(defn barber [shop] |
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
(ns my-ns.core | |
(:require [clojure.core.async :refer | |
[timeout thread alt! alts! chan go-loop <! >! put! chan close!]])) | |
(defn takes-a-while [chan x] | |
(println "starting long running query") | |
(thread (Thread/sleep 5000) | |
(put! chan x))) | |
(defn run-it [] |
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
(ns cljs.core-test-generative | |
(:require [clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop])) | |
(def samples 100) | |
(def shuffle-prop | |
(prop/for-all [v (gen/such-that not-empty (gen/vector gen/any))] | |
(seq (shuffle v)))) |
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
(defn percentile [xs n] | |
(let [idx (Math/floor (* (count xs) (/ n 100)))] | |
(nth (sort xs) idx))) | |
(defn percentiles [xs] | |
(let [p (partial percentile xs)] | |
(into {} (map (juxt (comp keyword str) p) [50 90 95 99])))) |
NewerOlder