Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Created April 10, 2015 15:23
Show Gist options
  • Save Jacoby6000/7718a27b6fe19e034ed1 to your computer and use it in GitHub Desktop.
Save Jacoby6000/7718a27b6fe19e034ed1 to your computer and use it in GitHub Desktop.
import scalaz.{Tag, @@}
trait EmailAddress
implicit def EmailAddress(str: String): String @@ EmailAddress = {
require(str.matches("[^@]+@.*"), "String is not an email")
// ^ Over simplified email regex, I know.
// Also it should be defined elsewhere so it's not compiled everytime. I know. This is just an example :)
Tag[String,EmailAddress](str)
}
case class SomeClass(email: String @@ EmailAddress)
val foo = SomeClass("[email protected]")
foo.email + " is a string, so we treat it like a string."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment