Possible Duplicate:
Searching the Scala documentation for #::
I'm looking through the docs of Stream
The filter method has this code:
def naturalsFrom(i: Int): Stream[Int] = i #:: naturalsFrom(i + 1)
naturalsFrom(1) 10 } filter { _ % 5 == 0 } take 10 mkString(", ")
What is the #:: operator? Does this map to a function call somewhere?
As SHildebrandt says, #:: is the cons operator for Streams.
In other words, #:: is to streams what :: is to Lists
val x = Stream(1,2,3,4) //> x : scala.collection.immutable.Stream[Int] = Stream(1, ?)
10#::x //> res0: scala.collection.immutable.Stream[Int] = Stream(10, ?)
val y = List(1,2,3,4) //> y : List[Int] = List(1, 2, 3, 4)
10::y //> res1: List[Int] = List(10, 1, 2, 3, 4)
x #:: xs
returns
Stream.cons(x, xs)
which returns a Stream of an element x followed by a Stream xs.
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