Skip to content

Commit

Permalink
++Docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutpalm committed Apr 12, 2024
1 parent f0277ce commit b81fa0e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/righttypes/types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit b81fa0e

Please sign in to comment.