Skip to content

Commit 1748c1b

Browse files
committed
describe on a tuple where at least one entry has a defined :key will return a map of the entries with a key instead of a vector of all the entries.
1 parent 6028cb0 commit 1748c1b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Versions prior to v0.1.0 are considered experimental, their API may change.
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `describe` on a tuple where at least one entry has a defined :key will return
13+
a map of the entries with a key instead of a vector of all the entries.
14+
1015
## [0.0.7] - 2020-09-20
1116

1217
### Fixed

src/minimallist/core.cljc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,16 @@
288288
(implies (contains? model :condition-model)
289289
(:valid? (-describe context (:condition-model model) data))))]
290290
{:valid? valid?
291-
:desc (mapv :desc entries)})
291+
:desc (if (and (= (:type model) :sequence)
292+
(some #(contains? % :key) (:entries model)))
293+
(->> (map (fn [model-entry described-entry]
294+
(when (contains? model-entry :key)
295+
[(:key model-entry) (:desc described-entry)]))
296+
(:entries model)
297+
entries)
298+
(filter some?)
299+
(into {}))
300+
(mapv :desc entries))})
292301
{:valid? false})
293302
:alt (let [[key entry] (first (into []
294303
(comp (map-indexed (fn [index entry]

test/minimallist/core_test.cljc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@
350350
[1 2] :invalid
351351
[1] :invalid]
352352

353+
(h/tuple (h/fn int?)
354+
[:text (h/fn string?)])
355+
[[1 "a"] {:text "a"}]
356+
357+
(h/tuple [:number (h/fn int?)]
358+
[:text (h/fn string?)])
359+
[[1 "a"] {:number 1, :text "a"}]
360+
353361
;; sequence - :count-model
354362
(-> (h/sequence-of (h/fn any?))
355363
(h/with-count (h/val 3)))

0 commit comments

Comments
 (0)