I'm proficient in Python but a noob at Scala. I'm about to write some dirty experiment code in Scala, and came across the thought that it would be really handy if Scala had a function like help()
in Python. For example, if I wanted to see the built-in methods for a Scala Array
I might want to type something like help(Array)
, just like I would type help(list)
in Python. Does such a thing exist for Scala?
I think tab completion is the closest thing to Python's help.
There is also a dated but still relevant post from @dcsobral on using Scala documentation and Scalex which is similar to Hoogle for Haskell.
This is the tab completion in the 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
This is for the methods on the class Array
. Not sure why this doesn't show value members after a.
scala> val a = Array(1,2,3)
a: Array[Int] = Array(1, 2, 3)
scala> a.
apply asInstanceOf clone isInstanceOf length toString update
Though a little daunting at times tab completion on a method shows the method signatures. Here it is for 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]
sbt-man is a sbt plugin for looking up scaladoc. The sbt console
command starts the Scala REPL with project classes and dependencies on the classpath
Example:
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.
I do not know of one built-in but you should use Scaladocs to find the same information.
Unless you use eclipse which has an auto complete with short explanations. For instance it will give you all the commands for arrays after typing 'array.'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With