Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching the Scala documentation for #::

I am trying to find the documentation for the Scala operator method #::. I believe that it is defined in the Stream class because of an example I found that uses it.

My question is not particular to this method (although I would like to know where the docs are), but how to search the Scala docs in general. I tried entering #:: in the search box in the upper left of the documentation page (2.8.1), but found nothing.

like image 793
Ralph Avatar asked Dec 29 '10 12:12

Ralph


People also ask

How to learn Scala programming language?

Bite-sized introductions to core language features. Learn Scala by reading a series of short lessons. Online Courses, Exercises, & Blogs. Printed and digital books about Scala. Take you by the hand through a series of steps to create Scala applications. API documentation for every version of Scala.

What's new in Scala version 3?

The new Scala version 3 comes with a completely new implementation of the documentation generator Scaladoc, rewritten from scratch. In this article you can find highlights of new features that are or will be introduced to Scaladoc. For general reference, visit Scaladoc manual.

How do I generate scaladoc API documentation?

To generate Scaladoc API documentation, document your code using Scaladoc tags, and then create the documentation using an SBT task or the scaladoc command. You can mark up your source code using Scaladoc tags as well as a wiki-like syntax. The following code shows many of the Scaladoc tags and a few of the wiki-style markup tags:

What are common scaladoc tags?

Most Scaladoc tags are similar to Javadoc tags. Common Scaladoc tags are shown in Table 14-1. Table 14-1. Common Scaladoc tags The author of the class. Multiple tags are allowed. Documentation you want to provide for the constructor.


2 Answers

I suggest using the Reference Index - it's designed specifically to look for any kind of symbol (class, traits, methods, vals, vars) regardless of it's hierarchical position - contrasting with the Scaladoc's left index which doesn't show inner classes, traits or objects.

Unfortunately it's only available in the nightly. You can see the whole thing at nightly Scaladoc. Notice the upper box in the left frame, above the index.

Hope it will be bundled with Scala 2.9.0.

Edit As of 2.9.0, the reference index started to be bundle with Scaladoc. No need to go to the nightly docs now.

like image 176
pedrofurla Avatar answered Oct 01 '22 04:10

pedrofurla


As others have already mentioned, #:: is defined on scala.collection.immutable.Stream.ConsWrapper. I just wanted to take a minute to elaborate on why that is.

In general, to call an operator on an object, that object needs to exist. However, the idea with a Stream is the tail of the stream is not evaluated until it needs to be. So consider the following stream:

def fibs(a:Int,b:Int):Stream[Int] = a #:: fibs(b,a+b)

Ordinarily, we would need to evaluate the recursive fibs call so that we could call the #:: operator on it. This would lead to runaway recursion. This is NOT what we want. What we want is for the reciever to be a by-name Stream. Hence the ConsWrapper:

The constructor for ConsWrapper is class ConsWrapper[T](tail: => Stream[T]) taking a by-name Stream, and it's created through an implicit conversion Stream.consWrapper[T](stream: => Stream[T]), which also takes a by-name Stream.

Hence, we have performed an implicit conversion on the result of a function that has not yet been called, and we have mimiced the effect of calling #:: with a by-name this reference.

like image 21
Ken Bloom Avatar answered Oct 01 '22 03:10

Ken Bloom