Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
scala.util.Try块的返回值_Scala - Fatal编程技术网

scala.util.Try块的返回值

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

我对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'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: