【发布时间】:2020-06-24 07:40:52
【问题描述】:
我正在尝试对 scala 基本操作进行一些动手操作,但在以下示例代码中卡住了
def insuranceRateQuote(a: Int, tickets:Int) : Either[Exception, Double] = {
// ... something
Right(Double)
}
def parseInsuranceQuoteFromWebForm(age: String, numOfTickets: String) : Either[Exception, Double]= {
try{
val a = Try(age.toInt)
val tickets = Try(numOfTickets.toInt)
for{
aa <- a
t <- tickets
} yield insuranceRateQuote(aa,t) // ERROR HERE
} catch {
case _ => Left(new Exception)}
}
我得到的错误是它说found Try[Either[Exception,Double]]
我不明白为什么它是 Try of Either 下的包装器
PS - 这一定不是在 scala 中做的完美方式,所以请随意发布您的示例代码 :)
【问题讨论】:
-
将 Try 包裹在
try中是很奇怪的。
标签: scala try-catch for-comprehension either