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:
(use 'clojure.core.async) | |
(def output (atom [])) | |
(defn producer [ctrl k] | |
(go (loop [i 0] | |
(when-let [c (<! ctrl)] | |
(>! c [k i]) | |
(>! ctrl c) | |
(recur (inc i)))))) |
(defn thread-and | |
"Call each of the fs on a separate thread. Return logical | |
conjunction of the results. Short-circuit (and cancel the calls | |
to remaining fs) on first falsey 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] |
(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] |
(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 [ret (promise) | |
fps (promise)] | |
(deliver fps | |
(doall (for [f fs] | |
(let [p (promise)] |
;(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] |
I hereby claim:
To claim this, I am signing this object:
(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))))) |
;;; 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 |
;; 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) |