What does the # :: operator mean?

I understand that this is probably a simple question, but what is the "# ::" achievement in the bottom line of code. Is this a particular minus difference?

def from(n: Int): Stream[Int] = n #:: from(n + 1) 
+6
source share
4 answers

This operator is used to create threads as opposed to lists. Consider the same code fragment with simple minuses:

 def from(n: Int): List[Int] = n :: from(n + 1) 

running this method will StackOverflowError . But with Stream[Int] tail is evaluated lazily only when necessary (and already calculated values ​​are remembered).

+11
source

This is equivalent to :: for lists, but used with Streams

That is, n becomes the head of the stream, where from(n+1) is the tail

+6
source

This means creating a Stream object.

It is identical to cons for a list β€” instead of :: , which always creates a list, #:: always creates a stream.

+1
source

A bit late, but there is http://scalex.org/ which is very nice to block such things (google is really a mess on anything non-alpha -numeric)! Good luck

0
source

All Articles