2 ms·
This is a good idea I believe. While I agree it would be convenient to have it in the standard library of more languages, it can be implemented in strongly typ
by mejutoco 4y ago
This is a good idea I believe.
While I agree it would be convenient to have it in the standard library of more languages, it can be implemented in strongly typed languages, using something like Newtype in haskell. In Typescript, for example, it could be:
type SanitizedString = string
And somewhere you have a function getSanitizedString and if you don't call that the type system will complain.
Same could be done to represent a distance in Km or miles:
type DistanceKm = number
type DistanceMiles = number
And then functions can explicitly use any of them or only some (we could define some function multiplying them to allow 2 arguments only if they are the same type).