GenTraversableOnce[B] 是 Array[File] 的父类型吗?
Is GenTraversableOnce[B] parent type of Array[File]?
flatMap
的定义:
def flatMap[B](f: (A) ⇒ GenTraversableOnce[B]): Array[B]
要在目录中创建 List
个文件:
def recursiveListFiles(f: File): Array[File] = {
val these = f.listFiles
these ++ these.filter(_.isDirectory).flatMap(f => recursiveListFiles(f))
}
flatMap
接受一个函数参数,它也接受一个参数并且 returns
输入 GenTraversableOnce[B]
在 Array
和 GenTraversableOnce
之间存在分层公共类型,就好像没有 link 那么 Array[File]
不应该是 GenTraversableOnce[B]
的有效类型?
正在看
Array
API : http://www.scala-lang.org/api/2.10.4/#scala.Array
GenTraversableOnce
API : http://www.scala-lang.org/api/2.10.4/#scala.collection.GenTraversableOnce
似乎没有 Link ?
存在从 Array
to ArrayOps
的隐式转换,它继承了 GenTraversableOnce
。
来自 ScalaDocs :
Two implicit conversions exist in scala.Predef that are frequently
applied to arrays: a conversion to scala.collection.mutable.ArrayOps
(shown on line 4 of the example above) and a conversion to
scala.collection.mutable.WrappedArray (a subtype of
scala.collection.Seq). Both types make available many of the standard
operations found in the Scala collections API
至于两者的区别:
The conversion to ArrayOps is temporary, as all operations defined on
ArrayOps return an Array, while the conversion to WrappedArray is
permanent as all operations return a WrappedArray.
如 Array
的链接 scaladoc 所述:
Two implicit conversions exist in scala.Predef that are frequently applied to arrays: a conversion to scala.collection.mutable.ArrayOps (shown on line 4 of the example above) and a conversion to scala.collection.mutable.WrappedArray (a subtype of scala.collection.Seq).
Array
没有继承自 GenTraversableOnce
,但是在 scala.Predef
中看到了从 Array
到 ArrayOps
的隐式转换 here and here . ArrayOps
确实继承自 GenTraversableOnce
.
flatMap
的定义:
def flatMap[B](f: (A) ⇒ GenTraversableOnce[B]): Array[B]
要在目录中创建 List
个文件:
def recursiveListFiles(f: File): Array[File] = {
val these = f.listFiles
these ++ these.filter(_.isDirectory).flatMap(f => recursiveListFiles(f))
}
flatMap
接受一个函数参数,它也接受一个参数并且 returns
输入 GenTraversableOnce[B]
在 Array
和 GenTraversableOnce
之间存在分层公共类型,就好像没有 link 那么 Array[File]
不应该是 GenTraversableOnce[B]
的有效类型?
正在看
Array
API : http://www.scala-lang.org/api/2.10.4/#scala.Array
GenTraversableOnce
API : http://www.scala-lang.org/api/2.10.4/#scala.collection.GenTraversableOnce
似乎没有 Link ?
存在从 Array
to ArrayOps
的隐式转换,它继承了 GenTraversableOnce
。
来自 ScalaDocs :
Two implicit conversions exist in scala.Predef that are frequently applied to arrays: a conversion to scala.collection.mutable.ArrayOps (shown on line 4 of the example above) and a conversion to scala.collection.mutable.WrappedArray (a subtype of scala.collection.Seq). Both types make available many of the standard operations found in the Scala collections API
至于两者的区别:
The conversion to ArrayOps is temporary, as all operations defined on ArrayOps return an Array, while the conversion to WrappedArray is permanent as all operations return a WrappedArray.
如 Array
的链接 scaladoc 所述:
Two implicit conversions exist in scala.Predef that are frequently applied to arrays: a conversion to scala.collection.mutable.ArrayOps (shown on line 4 of the example above) and a conversion to scala.collection.mutable.WrappedArray (a subtype of scala.collection.Seq).
Array
没有继承自 GenTraversableOnce
,但是在 scala.Predef
中看到了从 Array
到 ArrayOps
的隐式转换 here and here . ArrayOps
确实继承自 GenTraversableOnce
.