我试图分析下面的一段Scala代码:斯卡拉:选项,有的和ArrowAssoc操作
import java.nio.file._
import scala.Some
abstract class MyCustomDirectoryIterator[T](path:Path,someNumber:Int, anotherNum:Int) extends Iterator[T] {
def getCustomIterator(myPath:Path):Option[(DirectoryStream[Path],
Iterator[Path])] = try {
//we get the directory stream
val str = Files.newDirectoryStream(myPath)
//then we get the iterator out of the stream
val iter = str.iterator()
Some((str -> iter))
} catch {
case de:DirectoryIteratorException =>
printstacktrace(de.getMessage)
None
}
如何interpert这段代码:Some((str -> iter))
是的,它返回类型的值:
Option[(DirectoryStream[Path], Iterator[Path])]
- >运算符是,尽我的理解,ArrowAssoc从scala.Predef包。
implicit final class ArrowAssoc[A] extends AnyVal
但我还是不明白什么 - >东西是做给我类型的返回值:
Option[(DirectoryStream[Path], Iterator[Path])]
Scala的专家在这里能投入更多的光对此有何看法?有没有办法以更可读的方式编写“一些(..)”的东西?不过,我理解Some的作用。
我不认为有任何更好的表达方式,除了使用逗号而不是' - >'。为什么地球上是'scala.Some'被导入?过度的IDE? – 2015-03-31 21:54:50