Skip to content

Instantly share code, notes, and snippets.

@kamekoopa
Created March 26, 2014 06:47
Show Gist options
  • Save kamekoopa/9777938 to your computer and use it in GitHub Desktop.
Save kamekoopa/9777938 to your computer and use it in GitHub Desktop.
私と仕事どっちが大事なの!
trait DocchiGaDaiji[A, B] {
def docchi(a: A, b: B): Either[A, B]
}
object WatashiToShigoto {
case class Watashi
case class Shigoto
implicit object WatashiToShigotoDocchigaDaiji extends DocchiGaDaiji[Watashi, Shigoto]{
override def docchi(a: Watashi, b: Shigoto): Either[Watashi, Shigoto] = {
Right(b)
}
}
}
object Main {
import WatashiToShigoto._
def main(args: String*): Either[Watashi, Shigoto] = {
docchi(Watashi(), Shigoto())
}
def docchi[A, B](a: A, b: B)(implicit ev: DocchiGaDaiji[A, B]): Either[A, B] = {
ev.docchi(a, b)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment