In case you're unfamiliar with scala, the as method is the one defined in the implicit class TagWrapper. During compile time, this gets translated into completely type safe code.
We made good experiences with tagged types, because they are very lightweight and serialize/deserialize well.
They are a good example of getting the benefit of type safety without making the code much harder to write.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article!
In my last project, we used tagged types to further discriminate types of Strings from each other. The Implementation (in Scala) is straightforward:
We declared them with type aliases to have more human readable types. Taking your examples, that might look like this:
They still can be used like values of the base type:
and here's how we used them with literals:
In case you're unfamiliar with scala, the
as
method is the one defined in the implicit classTagWrapper
. During compile time, this gets translated into completely type safe code.We made good experiences with tagged types, because they are very lightweight and serialize/deserialize well.
They are a good example of getting the benefit of type safety without making the code much harder to write.