简体   繁体   中英

java.io.Serializable to Seq Scala

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(aa@aa.com, bb@bb.com)), 
TableInfo(Y,YY,List(aa@aa.com, bb@bb.com)))

[Code]:

scala.util.Either[Exception,List[TableInfo]] = 
Right(List(TableInfo(X,XX,List(aa@aa.com, bb@bb.com)), 
TableInfo(Y,YY,List(aa@aa.com, bb@bb.com))))

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

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

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) => s
  case Right(i) => throw 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM