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 = "ed@you.com"
- s match {
- case EMail(user, domain) => println(user + " at " + domain)
- case _ => println("not an email address")
- }
- //val ss = List(s, s, "sue@me.com","sue@me.com")
- //val ss = List(s,"sue@me.com","sue@me.com")
- val ss = List("sue@me.com","sue@me.com", 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