我精通Python,但对Scala一无所知。我即将用Scala编写一些肮脏的实验代码,我突然想到,如果Scala在Python中有一个类似help()
的函数,那将非常方便。例如,如果我想查看Scala Array
的内置方法,我可能想键入类似help(Array)
的内容,就像在Python中键入help(list)
一样。Scala有这样的东西吗?
我不知道有内置的,但您应该使用Scaladocs来查找相同的信息。
除非你使用eclipse,它有一个带有简短解释的autocomplete。例如,在键入"array."之后,它将为您提供数组的所有命令。
我认为选项卡完成是最接近Python帮助的事情。
@dcsobral也发布了一篇关于使用Scala文档和Scalex的过时但仍然相关的帖子,这篇帖子类似于Haskell的Hoogle。
这是Object
Array
中的选项卡完成。
scala> Array.
apply asInstanceOf canBuildFrom concat copy
empty emptyBooleanArray emptyByteArray emptyCharArray emptyDoubleArray
emptyFloatArray emptyIntArray emptyLongArray emptyObjectArray emptyShortArray
fallbackCanBuildFrom fill isInstanceOf iterate newBuilder
ofDim range tabulate toString unapplySeq
这是针对类Array
上的方法。不确定为什么a.
之后没有显示值成员
scala> val a = Array(1,2,3)
a: Array[Int] = Array(1, 2, 3)
scala> a.
apply asInstanceOf clone isInstanceOf length toString update
尽管有时有点令人生畏,但方法上的制表符完成会显示方法签名。这是给Array.fill
的
def fill[T](n1: Int, n2: Int)(elem: => T)(implicit evidence$10: reflect.ClassTag[T]): Array[Array[T]]
def fill[T](n1: Int, n2: Int, n3: Int)(elem: => T)(implicit evidence$11: reflect.ClassTag[T]): Array[Array[Array[T]]]
def fill[T](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T)(implicit evidence$12: reflect.ClassTag[T]): Array[Array[Array[Array[T]]]]
def fill[T](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T)(implicit evidence$13: reflect.ClassTag[T]): Array[Array[Array[Array[Array[T]]]]]
def fill[T](n: Int)(elem: => T)(implicit evidence$9: reflect.ClassTag[T]): Array[T]
console
命令用项目类和类路径上的依赖项启动Scala REPL
示例:
man Traversable /:
[man] scala.collection.Traversable
[man] def /:[B](z: B)(op: (B ⇒ A ⇒ B)): B
[man] Applies a binary operator to a start value and all elements of this
collection, going left to right. Note: /: is alternate syntax for foldLeft;
z /: xs is the same as xs foldLeft z. Note: will not terminate for infinite-
sized collections. Note: might return different results for different runs,
unless the underlying collection type is ordered. or the operator is
associative and commutative.
类似地,IDEA有其"Quick Documentation Look up"命令,该命令适用于Scala以及Java(-Doc)JAR和源代码文档注释。
在scala中,您可以尝试使用以下。。(类似于我们在python中使用的)。。
python中的help(RDD1)将为您提供RDD1描述和完整的详细信息。
Scala>RDD1.[tab]
在点击选项卡时,您会发现指定RDD1可用的选项列表,类似于eclipse中的选项。