Fork me on GitHub
#malli
<
2021-01-20
>
ordnungswidrig09:01:41

@smchugh230395 can you use a set as the collection type?

Samuel McHugh09:01:54

That's a good idea but there is an order on the elements of the collection in my particular use-case. I can set up other ways of ensuring that only unique items enter the collection though so it isn't critical that Malli supports it out of the box.

ordnungswidrig09:01:39

I see. So “ordered set” is what you need I guess.

ordnungswidrig09:01:19

(m/validate [:and [:sequential any?] (fn [c] (= (count c) (count (set c)))) something like this?

🙌 3
Samuel McHugh14:01:11

good one, I think i'll go with this

ordnungswidrig14:01:35

Pretty sure this one of the least optimized way to check for distinct elements (reduce (fn [xs x] (if (xs s) (reduced false) (conj xs s))) #{} coll) might be faster.

ikitommi10:01:22

JSON Schema has “uniqueItems” attribute, I guess sequences could have :distict boolean property?

ikitommi10:01:46

… would be [:sequential {:distinct true} any?]

emccue14:01:21

I am somewhat meh on the coupling to json schema

emccue14:01:39

is there some usecase or justification i am missing?