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
;; some speed tests of functions to access nested properties in JS objects. | |
(def test-data (->> (into {} (for [k1 (range 10)] | |
[k1 (into {} (for [k2 (range 10)] | |
[k2 (into {} (for [k3 (range 10)] | |
[k3 k3]))]))])) | |
(clj->js))) | |
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 deep-merge | |
"Recursively merges maps. If vals are not maps, the last value wins." | |
[& vals] | |
(if (every? map? vals) | |
(apply merge-with deep-merge vals) | |
(last vals))) | |
(defn deep-merge-with | |
"Like merge-with, but merges maps recursively, applying the given fn | |
only when there's a non-map at a particular level." |
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 -inheritable* | |
[var] | |
(let [*i (doto (proxy [InheritableThreadLocal] [] | |
;; This is where the magic happens. | |
;; childValue is evaluated in the parent thread where bindings should still valid. | |
(childValue [{:keys [bindings]}] | |
(let [new-bindings (merge bindings (get-thread-bindings))] | |
{:bindings new-bindings | |
:get-val (fn [] (with-bindings new-bindings | |
(deref var)))}))) |
OlderNewer