Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env scala -feature
- object EMail {
- //object EMail extends ((String, String) => String) {
- //object EMail extends Function2[String, String, String] {
- //def apply(user: String, domain: String) = user + "@" + domain
- def unapply(str: String): Option[(String,String)] = {
- val parts = str split "@"
- if (parts.length == 2) Some(parts(0), parts(1)) else None
- }
- }
- val s: Any = "[email protected]"
- s match {
- case EMail(user, domain) => println(user + " at " + domain)
- case _ => println("not an email address")
- }
- //val ss = List(s, s, "[email protected]","[email protected]")
- //val ss = List(s,"[email protected]","[email protected]")
- val ss = List("[email protected]","[email protected]", s, s, s)
- ss match {
- case EMail(u1, d1) :: EMail(u2, d2) :: _ if (u1 == u2) => println(s"$u1 has a dupe")
- case _ => println("not sure")
- }
Add Comment
Please, Sign In to add comment