- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
object Main extends App {
object Email {
def apply(user: String, host: String) = user + "@" + host
def unapply(input: String): Option[(String, String)] = {
input.indexOf("@") match {
case x if (x > 0) => Some((input.substring(0, x), input.substring(x + 1)))
case _ => None
}
}
}
"[email protected]" match {
case Email(user, host) => println("See user <" + user + "> at domain <" + host + ">")
case _ => println("Well...")
}
"lol" match {
case Email(user, host) => println("Wow... strange email")
case _ => println("OK, <lol> is not an email")
}
}