Slide 23
Slide 23 text
// ࣮ࡍͷಈ࡞
object SayOps {
implicit val helloTeacherSay: Say[Hello, Teacher] = new Say[Hello, Teacher] {
def say(self: Hello, target: Teacher): Unit = {
println(s"͓Α͏͍͟͝·͢ɻ${target.name}ઌੜ")
}
}
implicit val helloFriedSay: Say[Hello, Friend] = new Say[Hello, Friend] {
def say(self: Hello, target: Friend): Unit = {
println(s"͋ ${target.name}")
}
}
implicit val goodbyeTeacherSay: Say[Goodbye, Teacher] = new Say[Goodbye,
Teacher] {
def say(self: Goodbye, target: Teacher): Unit = {
println(s"${target.name}ઌੜɺ͞Α͏ͳΒ")
}
}
implicit val goodbyeFriendSay: Say[Goodbye, Friend] = new Say[Goodbye,
Friend] {
def say(self: Goodbye, target: Friend): Unit = {
println(s"·ͨͶ ${target.name}")
}
}
}
分岐後の処理が独立しているのがポイント
(ifなどの分岐の中にない)