core-typed 2024-08-09

I'm curious is there a way to make a String type that has a max length?

Maybe? Try (t/I t/Str (t/CountRange 0 10)) for strings of 10 chars or less.

There might be a few missing pieces but some of the building blocks are there.

I'm not sure if (<= (count s) 10) will infer this type (might need some tweaks to the checker). I don't know if t/pred supports t/CountRange but generating a predicate from the type might be useful.

Yeah this should work.

(defalias String<=10 (t/I t/Str (t/CountRange 0 10)))
(def string<=10? (t/pred String<=10))

That works thanks!

🎉 1

Note that CountRange max is inclusive.

👍 1

Ok turns out I wasn't actually hitting that code. When I test it more in depth that pred only returns false for everything.

I tested it with your exact example

thanks I'll take a look.

also pushed some perf/memory improvements in the compiled preds.

❤️ 1