• Turun@feddit.de
    link
    fedilink
    arrow-up
    22
    ·
    9 months ago

    So the core concept is that when you validate some property about input you should also transform the input into a new form that represents the new guarantee in the type system.

    This is very, closely related to the “make invalid states unrepresentable” concept. If we have validated our list to be non empty, we should return a non empty list - after all an empty list is now invalid and as such the type system should exclude that possibility.

    • bugsmithOPA
      link
      fedilink
      arrow-up
      13
      ·
      9 months ago

      Yes! The concepts are intertwined. I think the key take away, for me, is to lean heavily into your type system and allow that to do some of the heavy lifting. Accept that something like a username is not a string, but a subtype of a string (this has to be true if any validation is required, otherwise you’d just accept any valid string).