Aquí hay un ejemplo de "Programming Scala" (O'Reilly), página 158 en el Capítulo 7, "The Scala Object System", que adaptamos del blog de Daniel Scobral (http://dcsobral.blogspot .com/2009/06/catching-exceptions .html):
// code-examples/ObjectSystem/typehierarchy/either-script.scala
def exceptionToLeft[T](f: => T): Either[java.lang.Throwable, T] = try { Right(f)
} catch {
}
case ex => Left(ex)
def throwsOnOddInt(i: Int) = i % 2 match { case 0 => i
}
case 1 => throw new RuntimeException(i + " is odd!")
for(i <- 0 to 3) exceptionToLeft(throwsOnOddInt(i)) match {
}
case Left(ex) => println("exception: " + ex.toString) case Right(x) => println(x)
O es un tipo incorporado y este lenguaje es común en algunos lenguajes funcionales como alternativa a lanzar una excepción. Tenga en cuenta que Izquierda y Derecha son subtipos de Cualquiera. Personalmente, me gustaría que el tipo se llamara "O", por lo que podría escribir "Throwable O T".
Ah, y por cierto, el término "infijo" se usa para estos tipos. –