Created
October 27, 2020 18:35
-
-
Save rupeshtr78/d6e1c8e3e54b278bcdf0e6228ebf4e29 to your computer and use it in GitHub Desktop.
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
object Person { | |
def apply(fullName: String) = fullName | |
def unapply(fullName: String): Option[String] = { | |
if (!fullName.isEmpty) | |
Some(fullName.replaceAll("(?<=\\w)(\\w+)", ".")) | |
else | |
None | |
} | |
} | |
def extractors(person: Any): String = { | |
person match { | |
case Person(initials) => s"My initials are $initials" | |
case _ => "Could not extract initials" | |
} | |
} | |
val rupesh = Person("Rupesh T Raghavan") | |
println(extractors(rupesh)) //My initials are R. T R. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment