From b81fa0eddf06c1e730e58e4145a5a98efcbf9c35 Mon Sep 17 00:00:00 2001 From: David Orme Date: Fri, 12 Apr 2024 14:02:32 -0500 Subject: [PATCH] ++Docstring --- src/righttypes/types.clj | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/righttypes/types.clj b/src/righttypes/types.clj index 130cac5..ec96b43 100644 --- a/src/righttypes/types.clj +++ b/src/righttypes/types.clj @@ -634,7 +634,26 @@ this default is that optional map keys with typos won't be automatically detecte (defmacro indexed - "" + "Constructs a map of maps, where the outer map indexes the inner maps based on a unique key in the inner maps. + + `map-ctor` is a constructor to validate the inner maps. + `index-key` is a key whose value must be uniquely present in each inner map that will be used as the outer map's index. + + e.g.: Given: + + ``` + (def Person (T {:key keyword? :first-name string? :last-name string?})) + (def PersonDB (indexed Person :key)) + ``` + + one can now write and expect: + + ``` + (let [testee (PersonDB {:key :franken :first-name \"Franken\" :last-name \"Stein\"} + {:key :charlie :first-name \"Charlie\" :last-name \"Brown\"})] + (-> testee :franken :last-name) := \"Stein\" + (-> testee :charlie :last-name) := \"Brown\") + ```" [map-ctor index-key] (let [line-col (seq (meta &form)) pretty (fn [x] (if (instance? clojure.lang.Named x) (name x) (pr-str x)))