Created
November 8, 2021 04:58
-
-
Save j-thepac/735055d09ba85026d3bb2bc07ad6d288 to your computer and use it in GitHub Desktop.
scalaDomainPartialFunction
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
trait Activities | |
case class PersonWalk(km:Float) extends Activities | |
case class PersonTalk(words:String) extends Activities | |
class CompanionPerson { | |
val perform:PartialFunction[Activities,Unit]= { | |
case PersonWalk(km) => println(km) | |
case PersonTalk(words) => println(words) | |
case _ =>print("Not defined") | |
} | |
} | |
object CompanionTest extends App { | |
val person:CompanionPerson=new CompanionPerson() | |
person.perform(PersonTalk("hi")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment