diff options
author | Andre Polykanine A.K.A. Menelion ElensĂșlĂ« <andre@oire.org> | 2017-10-22 22:24:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-22 22:24:36 +0300 |
commit | d5308a8173e3c221819fce6e9f3daf001ea1f68e (patch) | |
tree | c1001372b87c51764ab3c26f715994f32233bcbe | |
parent | f03c79d7f33f064d204b12e6686d315b9ab68149 (diff) | |
parent | d86597d4991b907f3d1940daf9ce97ca0ecf68dd (diff) |
Merge pull request #2935 from jdjohnston/edn-tags
[edn/en] Improve the "Tagged Elements" section
-rw-r--r-- | edn.html.markdown | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/edn.html.markdown b/edn.html.markdown index 9ecfb24f..f47853f0 100644 --- a/edn.html.markdown +++ b/edn.html.markdown @@ -84,22 +84,26 @@ github/fork ; you can't eat with this #MyYelpClone/MenuItem {:name "eggs-benedict" :rating 10} -; Let me explain this with a clojure example. Suppose I want to transform that +; Let me explain this with a Clojure example. Suppose I want to transform that ; piece of EDN into a MenuItem record. (defrecord MenuItem [name rating]) -; To transform EDN to clojure values, I will need to use the built in EDN -; reader, edn/read-string +; defrecord defined, among other things, map->MenuItem which will take a map +; of field names (as keywords) to values and generate a user.MenuItem record -(edn/read-string "{:eggs 2 :butter 1 :flour 5}") +; To transform EDN to Clojure values, I will need to use the built-in EDN +; reader, clojure.edn/read-string + +(clojure.edn/read-string "{:eggs 2 :butter 1 :flour 5}") ; -> {:eggs 2 :butter 1 :flour 5} -; To transform tagged elements, define the reader function and pass a map -; that maps tags to reader functions to edn/read-string like so +; To transform tagged elements, pass to clojure.edn/read-string an option map +; with a :readers map that maps tag symbols to data-reader functions, like so -(edn/read-string {:readers {'MyYelpClone/MenuItem map->menu-item}} - "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") +(clojure.edn/read-string + {:readers {'MyYelpClone/MenuItem map->MenuItem}} + "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") ; -> #user.MenuItem{:name "eggs-benedict", :rating 10} ``` |