malli

https://github.com/metosin/malli :malli:
ordnungswidrig 2021-01-20T09:18:41.019Z

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

Samuel McHugh 2021-01-20T09:20:54.020800Z

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.

ordnungswidrig 2021-01-20T09:46:39.021300Z

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

ordnungswidrig 2021-01-20T09:52:19.022300Z

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

🙌 1
ikitommi 2021-01-20T10:46:22.023Z

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

ikitommi 2021-01-20T10:47:46.023800Z

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

ordnungswidrig 2021-01-20T11:32:22.024Z

interesting

emccue 2021-01-20T14:09:21.024200Z

I am somewhat meh on the coupling to json schema

emccue 2021-01-20T14:10:39.024400Z

is there some usecase or justification i am missing?

Samuel McHugh 2021-01-20T14:22:11.024700Z

good one, I think i'll go with this

ordnungswidrig 2021-01-20T14:51:35.024900Z

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.