Noel Yap Noel Yap - 9 months ago 51
Scala Question

More terse way to define Scala Stream object?

I have the following:

val notDivisibleBy2: Stream[Long] = 3L #:: 5L #:: + 2)

is removed, a
is emitted. Is there a way to have the tail calculation work so that
doesn't have to be specified?

Answer Source

You are entering an infinite loop when you remove 5L and then call the tail function. As you can see, the tail of notDivisibleBy2 is + 2). You therefore need to remove both 5L and the call to tail.

val notDivisibleBy2: Stream[Long] = 3L #:: + 2)