I just wanted to clarify something about partially defined functions in Scala. I looked at the docs and it said the type of a partial function is PartialFunction[A,B]
In addition to other answers, if by "multiple accepted types" you mean that you want the same function accept e.g. String
, Int
and Boolean
(and no other types), this is called "union types" and isn't supported in Scala currently (but is planned for the future, based on Dotty). The alternatives are:
Any
for the above case). This is what orElse
chains will do.Either[String, Either[Int, Boolean]]
. This is fine if you have two types, but becomes ugly quickly.