This file contains hidden or 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
| scala> new EmailAddress("@example.com") {} | |
| <console>:15: error: illegal inheritance from sealed class EmailAddress | |
| new EmailAddress(""){} |
This file contains hidden or 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
| scala> class EvilEmailAddress(address: String) extends EmailAddress(address) | |
| <console>:14: error: illegal inheritance from sealed class EmailAddress | |
| class EvilEmailAddress(address: String) extends EmailAddress(address) |
This file contains hidden or 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
| sealed abstract case class EmailAddress(emailAddress: String) |
This file contains hidden or 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
| class EvilEmailAddress(address: String) extends EmailAddress(address) | |
| EmailClient.sendEmail(from = new EvilEmailAddress("luis@example.com"), to = new EvilEmailAddress("@example.com")) { | |
| ... | |
| } |
This file contains hidden or 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
| new EmailAddress(emailAddress) {} |
This file contains hidden or 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
| scala> EmailAddress("luis@example.com").map(_.copy(emailAddress = "@example.com")) | |
| <console>:13: error: value copy is not a member of EmailAddress | |
| EmailAddress("luis@example.com").map(_.copy(emailAddress = "@example.com")) | |
| ^ |
This file contains hidden or 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
| abstract case class EmailAddress(emailAddress: String) |
This file contains hidden or 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
| scala> EmailAddress("luis@example.com").map(_.copy(emailAddress = "@example.com")) | |
| res0: scala.util.Either[String,Either[String,EmailAddress]] = Right(Left(Invalid email address)) | |
| scala> for { | |
| | e1 <- EmailAddress("luis@example.com") | |
| | e2 <- e1.copy(emailAddress = "@example.com") | |
| | } yield e2 | |
| res1: scala.util.Either[String,EmailAddress] = Left(Invalid email address) |
This file contains hidden or 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
| case class EmailAddress(emailAddress: String) { | |
| def copy(emailAddress: String = emailAddress): Either[String, EmailAddress] = { | |
| EmailAddress(emailAddress) | |
| } | |
| } |
This file contains hidden or 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
| scala> val emailAddress = EmailAddress("luis@example.com") | |
| emailAddress: Either[String,EmailAddress] = Right(EmailAddress(luis@example.com)) | |
| scala> emailAddress.map(_.copy(emailAddress = "@example.com")) | |
| res0: scala.util.Either[String,EmailAddress] = Right(EmailAddress(@example.com)) |
NewerOlder