|
|
|
|
|
by 1-more
1008 days ago
|
|
In languages with tagged union types you do this a lot! Some Haskell pseudocode for ya module Email (Address, fromText, toText) where -- note we do not export the constructor of Address, just the type
data Address = Address Text
fromString :: Text -> Maybe Address
fromString =
-- you'd do your validation in here and return Nothing if it's a bad address.
-- Signal validity out of band, not in band with the data.
toText :: Address -> Text
toText (Address addr) = addr -- for when you need to output it somewhere
|
|