Skip to content

Instantly share code, notes, and snippets.

@ogatatsu
Forked from kmizu/Or.scala
Created January 4, 2011 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogatatsu/764717 to your computer and use it in GitHub Desktop.
Save ogatatsu/764717 to your computer and use it in GitHub Desktop.
implicit def l[A,B]: Either[A =:= A, A =:= B] = Left(=:=.tpEquals[A])
implicit def r[A,B]: Either[B =:= A, B =:= B] = Right(=:=.tpEquals[B])
def valueIsIntOrString[T](value: T)(implicit param: Either[T =:= String, T =:= Int]) = param match {
case Left(t2String) =>
println("value is String")
println(t2String(value))
case Right(t2Int) =>
println("value is Int")
println(t2Int(value))
}
valueIsIntOrString(100)
valueIsIntOrString("Foo")
// valueIsIntOrString(1.0) // Compilation Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment