Last active
September 11, 2015 22:58
-
-
Save nathanmarz/3280f4bed63d19d6935e to your computer and use it in GitHub Desktop.
Late bound parameterization with Specter
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
(def DATA {"a" [{"b" 1} {"b" 2}] "b" 11}) | |
;; Selectors that require parameters can be precompiled *without* the parameters. | |
;; The parameters are supplied later. | |
(def path (comp-paths keypath ALL keypath)) | |
;; These two selections are equivalent | |
(select (path "a" "b") DATA) | |
(select [(keypath "a") ALL (keypath "b")] DATA) | |
;; This function will now execute extremely efficiently. Before, without late-bound parameterization | |
;; this would run much slower because of the need to compose the path during the function call. With | |
;; late-bound parameterization, it's done beforehand and the parameters supplied when they're available. | |
(defn foo [k1 k2 data] | |
(select (path k1 k2) data)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment