I realise this is probably a simple question but what is ‘#::’ achieving in below line of code. Is it a special variance of cons ?
def from(n: Int): Stream[Int] = n #:: from(n + 1)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This operator is used to construct streams as opposed to lists. Consider the same code snippet with simple cons:
running this method will result in
StackOverflowError. But withStream[Int]tail is evaluated lazily only when it’s needed (and already computed values are remembered).