Home > Back-end >  java.io.Serializable to Seq Scala
java.io.Serializable to Seq Scala

Time:08-09

I have a case match statement that provides the following output. I'm trying to convert this into a sequence instead. Can you please help me with this?

java.io.Serializable = List(TableInfo(X,XX,List([email protected], [email protected])), 
TableInfo(Y,YY,List([email protected], [email protected])))

[Code]:

scala.util.Either[Exception,List[TableInfo]] = 
Right(List(TableInfo(X,XX,List([email protected], [email protected])), 
TableInfo(Y,YY,List([email protected], [email protected]))))

result match {
  case Left(s) => s
  case Right(i) => i
}

Complete Code: https://scastie.scala-lang.org/HT8wmYtsRF6DwzEkJYeygA

CodePudding user response:

Your code doesn't throw any exceptions right now. Based on the comments, it sounds like your intention is to extract a Right or throw whatever's on the Left. In that case, all you're missing is the throw keyword.

result match {
  case Left(s) => throw s
  case Right(i) => i
}

throw breaks the normal flow of control, so it returns Nothing, which is the unique subtype of all types in Scala. Thus, the common types of Nothing and whatever s is, is simply the type of s.

  • Related