scala.util.Try块的返回值
我对scala.util.Try API中的示例有一个问题。 案例成功率(v)=> … Success(v)//很明显,返回值是Success(value)scala.util.Try块的返回值,scala,Scala,我对scala.util.Try API中的示例有一个问题。 案例成功率(v)=> … Success(v)//很明显,返回值是Success(value) 案例失败(e)=> … 分开 它像递归一样再次调用了divide函数。它一直在呼唤自己,直到成功 例如,在repl中运行时 scala> divide Enter an Int that you'd like to divide: Enter an Int that you'd like to divide by: You must
案例失败(e)=> … 分开
它像递归一样再次调用了divide函数。它一直在呼唤自己,直到成功 例如,在repl中运行时
scala> divide
Enter an Int that you'd like to divide:
Enter an Int that you'd like to divide by:
You must've divided by zero or entered something that's not an Int. Try again!
Info from the exception: / by zero
Enter an Int that you'd like to divide:
我已经传递了分母值零,所以它再次调用了除法函数
希望,它会有帮助。这是因为该函数是递归的,总是等待用户的输入,所以当函数失败时,它只会说你搞糟了,然后再试一次
// Input any non-parsable Int should return an Failure(e) instance, right?
// Why is the return value divide, the method itself?
// What does returning divide mean?
scala> divide
Enter an Int that you'd like to divide:
Enter an Int that you'd like to divide by:
You must've divided by zero or entered something that's not an Int. Try again!
Info from the exception: / by zero
Enter an Int that you'd like to divide: