Created
April 10, 2015 15:23
-
-
Save Jacoby6000/7718a27b6fe19e034ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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