core-typed

2024-08-09T17:52:15.254099Z

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

2024-08-09T17:59:56.508449Z

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

2024-08-09T18:01:10.498719Z

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

2024-08-09T18:03:21.174539Z

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.

2024-08-09T18:05:20.861169Z

Yeah this should work.

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

2024-08-09T20:31:21.884039Z

That works thanks!

🎉 1
2024-08-09T20:44:33.326009Z

Note that CountRange max is inclusive.

👍 1
2024-08-09T21:19:49.136699Z

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

2024-08-09T21:19:57.385219Z

I tested it with your exact example

2024-08-09T22:30:01.278299Z

thanks I'll take a look.

2024-08-09T22:37:00.117239Z

found the problem

2024-08-09T23:23:06.007959Z

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

❤️ 1