Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access scala documentation from the repl?

First of all for the built in docs, and also for my own code.

Specifically, I want to get information similar to how in python you can call help() on a method or object to get information on just that object printed into the repl.

like image 724
wn- Avatar asked Jul 20 '11 20:07

wn-


People also ask

How do I access scala REPL?

We can start Scala REPL by typing scala command in console/terminal.

How does scala REPL work?

The Scala REPL is a tool (scala) for evaluating expressions in Scala. The scala command will execute a source script by wrapping it in a template and then compiling and executing the resulting program.

What is scala REPL?

The Scala REPL (Read-Eval-Print-Loop) is a development tool to interpret fragments of Scala code. It doesn't require too much setup or infrastructure and it is going to be essential during your learning journey. Using the REPL, you'll be able to play and experiment with the language by typing and evaluating code.


1 Answers

Scaladocs are generated as HTML, so you don't want them appearing in the REPL window. You might want to load docs in a browser from the REPL, however. You can do that by creating your own method like so (this one takes an instance; you could have it take an instance of Class[A] instead, if you prefer):

def viewdoc[A](a: A) {   val name = a.asInstanceOf[AnyRef].getClass.getName   val url = "http://www.scala-lang.org/api/current/index.html#"+name   val pb = new ProcessBuilder("firefox",url)   val p = pb.start   p.waitFor } 

If you want to get extra-clever, you could parse the name to point the web browser at Javadocs for java classes and Scaladocs for Scala classes and wherever you have your documentation for your classes. You also probably want to use a local source, file:///my/path/to/docs/index.html# instead of the API from the web. But I used this so you can try out

scala> viewdoc(Some(1)) 
like image 58
Rex Kerr Avatar answered Oct 08 '22 02:10

Rex Kerr