I hereby claim:
- I am michalmarczyk on github.
- I am michalmarczyk (https://keybase.io/michalmarczyk) on keybase.
- I have a public key ASDT-njSq0f89ZYOOhDYbdSb5MZkLq6LD_veaTD7vzegmQo
To claim this, I am signing this object:
| (alembic/distill '[org.clojure/data.avl "0.0.17"]) | |
| (alembic/distill '[net.cgrand/xforms "0.12.1"]) | |
| (require '[clojure.data.avl :as avl] | |
| '[net.cgrand.xforms :as x]) | |
| (defn join [keyfn xforms-map] | |
| (comp | |
| (x/multiplex xforms-map) |
| ;; Written to answer https://stackoverflow.com/questions/47254742/sort-primitive-array-with-custom-comparator-on-clojure | |
| ;; See https://gist.github.com/michalmarczyk/11bbfd0b19b6357f533b192bf9da84ac for the single-threaded version | |
| (defn order3 [xs] | |
| (let [rnd (java.util.Random.) | |
| a1 (double-array xs) | |
| a2 (long-array (alength a1))] | |
| (dotimes [i (alength a2)] | |
| (aset a2 i i)) | |
| (letfn [(quicksort [^long l ^long h] |
| ;; Written to answer https://stackoverflow.com/questions/47254742/sort-primitive-array-with-custom-comparator-on-clojure | |
| (defn order2 [xs] | |
| (let [rnd (java.util.Random.) | |
| a1 (double-array xs) | |
| a2 (long-array (alength a1))] | |
| (dotimes [i (alength a2)] | |
| (aset a2 i i)) | |
| (letfn [(quicksort [^long l ^long h] | |
| (if (< l h) |
| ;;; See the comment threads here: | |
| ;;; http://stackoverflow.com/questions/41677617/are-all-variables-in-clojure-constant | |
| (loop [x 1 | |
| f (fn [] x)] | |
| (if (== 1 x) | |
| (recur 0 f) | |
| (f))) | |
| ;= 1 |
| (defn validate-under [attr validator] | |
| (fn [m] | |
| (let [result (validator (get m attr))] | |
| [(empty? result) (v/nest attr result)]))) | |
| (comment | |
| (def example-v | |
| (v/validation-set | |
| (validate-under :foo (v/validation-set (v/presence-of :bar))))) |
I hereby claim:
To claim this, I am signing this object:
| ;(use '[clojure.tools.macro :only [symbol-macrolet]]) | |
| (defmacro letrec | |
| "Like let, but the bindings may be mutually recursive, provided that | |
| the heads of all values can be evaluated independently. | |
| This means that functions, lazy sequences, delays and the like can | |
| refer to other bindings regardless of the order in which they | |
| appear in the letrec form." | |
| [bindings & body] |
| (defn thread-or | |
| "Call each of the fs on a separate thread. Return logical | |
| disjunction of the results. Short-circuit (and cancel the calls to | |
| remaining fs) on first truthy value returned." | |
| [& fs] | |
| (let [ret (promise) | |
| fps (promise)] | |
| (deliver fps | |
| (doall (for [f fs] | |
| (let [p (promise)] |
| (defn thread-and | |
| "Computes logical conjunction of return values of fs, each of which | |
| is called in a future. Short-circuits (cancelling the remaining | |
| futures) on first falsey value." | |
| [& fs] | |
| (let [done (promise) | |
| ret (atom true) | |
| fps (promise)] | |
| (deliver fps (doall (for [f fs] | |
| (let [p (promise)] |
| (defn thread-or | |
| "Call each of the fs on a separate thread. Return logical | |
| disjunction of the results. Short-circuit (and cancel the calls to | |
| remaining fs) on first truthy value returned." | |
| [& fs] | |
| (let [futs-and-cs | |
| (doall (for [f fs] | |
| (let [c (chan)] | |
| [(future (>!! c (f))) c])))] | |
| (loop [futs-and-cs futs-and-cs] |