Last active
August 29, 2015 14:04
-
-
Save arichiardi/bb1015227d593d2c6307 to your computer and use it in GitHub Desktop.
Some snippet from my Clojure hacks.
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 com.andrearichiardi.utils | |
(:require [clojure.java.io :as io])) | |
(defn make-file-from-resource [name] (io/file (io/resource name))) | |
(defn to-bit-representation [^java.lang.Double d] | |
(-> (Double/doubleToRawLongBits d) (java.lang.Long/toBinaryString))) | |
(defmacro with-private-fns [[ns fns] & tests] | |
"Refers private fns from ns and runs tests in context." | |
`(let ~(reduce #(conj %1 %2 `(ns-resolve '~ns '~%2)) [] fns) | |
~@tests)) | |
(defn remove-and-cons | |
"Removes the items in coll for which (pred item) is true and then conses new-item. | |
Returns a lazy seq." | |
[pred new-item coll] | |
(lazy-seq (cons new-item (remove pred coll)))) | |
(defmacro do-if-not-value | |
"This macro executes (do side-effect not-found) if a value | |
corresponding to accessor cannot be found in coll" | |
[coll accessor not-found side-effect] | |
`(let [~'v# (get ~coll ~accessor)] | |
(if-not ~'v# | |
(do ~side-effect ~not-found) | |
~'v#))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment