r/Clojure • u/nimportfolio • Jun 07 '25
Announcement: RightTypes
RightTypes - Utilities to be used standalone or to enhance either or both of Specs/Malli with additional "type-y" things.
- Instead of defining what values are inside a set (type), we ask the reverse question: "What values are outside the set?" and behave like
identityotherwise. - Can we define identity values polymorphically, like Clojure already does with
niland sequences? With some caveats, yes we can! (e.g.: A generic monoid zero.) - A
failure?multimethod. Various data format utilities, many of which are useful for metaprogramming or interop.
- e.g.:
->kebab-case.
- e.g.:
This library tries hard not to be a framework so it can be adopted ad hoc. I've used this in production projects.
28
Upvotes
2
u/lgstein Jun 10 '25
If I understand correctly, the underlying idea is contracts, but instead of defining them rigidly on function args/returns, pervasive ad hoc "casting"/asserting is encouraged instead. This is an interesting tradeoff, mostly because it shifts more responsibility to the programmer, not annoying him in irrelevant cases.
I think this pattern should be explored more. It is interesting that you report positive experiences in production.
Some improvement suggestions/ideas:
4
u/morbidmerve Jun 07 '25
Quite nice i must say. Big w with using the result of T as a function and not needing a seperate “validate this value with this schema” function. The schema is a function. Brilliant.
Small note: how do you go about determining when something is valid without relying on catching errors?