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
;; in module code include this function: | |
(defn view-with-arg [view-fn arg] | |
(fn [v] (view-fn v arg))) | |
;; then foreign queries can be like this: | |
(foreign-select [(keypath :some-kid) (view (view-fn-with-arg contains? :some-swing))] swing-sessions-pstate) |
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
user=> (require 'test-ns) | |
Loading... | |
nil | |
user=> (require 'test-ns) | |
nil | |
user=> (require 'test_ns) | |
"Loading... | |
nil | |
user=> (require 'test_ns) | |
nil |
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
### Keybase proof | |
I hereby claim: | |
* I am nathanmarz on github. | |
* I am nathanmarz (https://keybase.io/nathanmarz) on keybase. | |
* I have a public key ASC_ykwTrU3q__CBRbHWiRnZZf_Hg8ZSu9ye2a3nM4NU9Qo | |
To claim this, I am signing this object: |
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
(let [ensure* (stay-then-continue (if-path empty? (terminal-val NONE)))] | |
(defdynamicnav ensure [& path] | |
(interleave (repeat (count path) ensure*) path) | |
)) | |
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1}}}) | |
;; => {} | |
(setval [:a (ensure :b :c)] NONE {:a {:b {:c 1} :d 2}}) | |
;; => {:a {:d 2}} |
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
Benchmark code: https://github.com/nathanmarz/specter/blob/master/scripts/benchmarks.clj#L176 | |
---------------------------------------------------------------------------------------------- | |
Benchmark: first value of a size 10 vector (10000000 iterations) | |
Avg(ms) vs best Code | |
261.98 1.00 (select-any FIRST data) | |
277.11 1.06 (select-any ALL data) | |
337.43 1.29 (select-first ALL data) | |
561.89 2.14 (first data) |
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
Specter 1.0 | |
Clojure 1.8.0 | |
Mac OSX 10.11.6 | |
Benchmark: namespace qualify keys of a small map (1000000 iterations) | |
Avg(ms) vs best Code | |
243.69 1.00 (setval [MAP-KEYS NAMESPACE] (str *ns*) data) | |
432.11 1.77 (reduce-kv (fn [m k v] (assoc m (keyword (str *ns*) (name k)) v)) {} data) | |
682.69 2.80 (into {} (map (fn [[k v]] [(keyword (str *ns*) (name k)) v])) data) |
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
Benchmark code at: https://github.com/nathanmarz/specter/blob/master/scripts/benchmarks.clj | |
Run against Clojure 1.7.0 and Java 1.7.0 on Mac OSX 10.11.6 | |
Benchmark: get value in nested map (2500000 iterations) | |
Avg(ms) vs best Code | |
53.528 1.00 (-> data (get :a) (get :b) (get :c)) | |
54.708 1.02 (-> data :a :b :c) |
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 fast-constantly [v] | |
(fn ([] v) | |
([a1] v) | |
([a1 a2] v) | |
([a1 a2 a3] v) | |
([a1 a2 a3 a4] v) | |
([a1 a2 a3 a4 a5] v) | |
([a1 a2 a3 a4 a5 a6] v) | |
([a1 a2 a3 a4 a5 a6 a7] v) | |
([a1 a2 a3 a4 a5 a6 a7 a8] v) |
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
Benchmark: transform values of a small map (1000000 iterations) | |
Avg(ms) vs best Code | |
141.61 1.00 (map-vals-map-iterable data inc) | |
146.86 1.04 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data) | |
156.66 1.11 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data) | |
161.20 1.14 (transform MAP-VALS inc data) | |
211.53 1.49 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data)) | |
227.91 1.61 (map-vals-map-iterable-transient data inc) | |
332.09 2.35 (transform [ALL LAST] inc data) |
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
(declarepath ConawWalker) | |
(providepath ConawWalker | |
(stay-then-continue | |
(cond-path map? MAP-VALS coll? ALL) | |
ConawWalker)) | |
(transform [ALL MAP-VALS ConawWalker (pred :tempid)] :tempid data) |
NewerOlder