This file contains hidden or 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 completing2 | |
| ([f] (completing2 f identity)) | |
| ([f cf] | |
| (fn | |
| ([] (f)) | |
| ([x] (cf x)) | |
| ([m k v] (f m k v))))) | |
| (defn transduce-kv | |
| ([xform f coll] (transduce-kv xform f (f) coll)) |
This file contains hidden or 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
| (defmacro either-> | |
| [expr & clauses] | |
| (assert (zero? (rem (count clauses) 3))) | |
| (let [g (gensym) | |
| steps (map (fn [[test then else]] `(if (reduced? ~g) | |
| ~g | |
| (if (-> ~g ~test) | |
| (-> ~g ~then) | |
| (reduced (-> ~g ~else))))) | |
| (partition 3 clauses))] |
This file contains hidden or 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
| :int? 1 vmap-into 314.527436 ns | |
| :int? 1 vmap-red 124.050875 ns | |
| :int? 1 vmap-ret 142.164359 ns | |
| :keyword? 1 vmap-into 291.031109 ns | |
| :keyword? 1 vmap-red 113.564282 ns | |
| :keyword? 1 vmap-ret 150.486043 ns | |
| :string? 1 vmap-into 339.743369 ns | |
| :string? 1 vmap-red 119.235523 ns | |
| :string? 1 vmap-ret 156.019188 ns | |
| :int? 2 vmap-into 405.677769 ns |
This file contains hidden or 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- pair | |
| [k v] | |
| (clojure.lang.MapEntry. k v)) | |
| (defn prod | |
| [xs ys] | |
| (persistent! | |
| (reduce | |
| (fn [acc x] | |
| (reduce |
This file contains hidden or 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
| ;;; | |
| ;;; see https://www.reddit.com/r/Clojure/comments/gcry9d/why_does_my_clojure_implementation_of_conways/ | |
| ;;; for initial implementation | |
| ;;; | |
| (ns gol.core | |
| (:gen-class) | |
| (:import | |
| [java.awt Color Graphics]) | |
| (:use seesaw.core |
This file contains hidden or 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 map-or-vec? | |
| [x] | |
| (or (map? x) (vector? x))) | |
| ;;; https://www.reddit.com/r/Clojure/comments/7wl7nt/get_a_list_of_all_paths_in_a_nested_map/ | |
| (defn paths | |
| ([m] | |
| (paths [] [] m)) | |
| ([ps ks m] |
This file contains hidden or 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
| (defmacro cond* | |
| [& clauses] | |
| (when clauses | |
| (let [p (first clauses) | |
| return? (:return (meta p))] | |
| (if return? | |
| `(if ~p | |
| ~p | |
| (cond* ~@(next clauses))) | |
| `(if ~p |
This file contains hidden or 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 dissoc-in | |
| [m ks] | |
| (let [[k & ks] ks] | |
| (if ks | |
| (let [found (find m k)] | |
| (if found | |
| (assoc m k (dissoc-in (val found) ks)) | |
| m)) | |
| (dissoc m k)))) |
This file contains hidden or 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 get-lens [k] (fn [m] (get m k))) | |
| (defn get-in-lens | |
| [ks] | |
| (reduce | |
| (fn [f k] | |
| (fn [m] | |
| (let [lens (get-lens k)] | |
| (lens (f m))))) | |
| identity |
This file contains hidden or 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 camel->snake | |
| [s] | |
| (-> s | |
| (clojure.string/replace #"([^_A-Z])([A-Z])" "$1-$2") | |
| clojure.string/lower-case)) | |
| (defn gen-param* | |
| [c] | |
| (-> | |
| c |