Hi Vishnu,
`forAll(f)` should always return `true` for the empty stream, no matter what `f` is. Think about it this way:
What would you expect the following to return?
!s.forAll(f)
I'd expect that negation to be true precisely when there are some elements in `s` that don't match `f`. I would expect "not all the elements match" and "some of the elements don't match" to be the same. That is, if we were to assert "there are no elements in the stream not matching f" (obviously true for the empty stream), that should be the same thing as saying "all elements in the stream match f".
If that's not convincing, think about it another way:
Given two streams `s1` and `s2`, if we say s1.forAll(f) && s2.forAll(f) that should be the same as saying (s1 ++ s2).forAll(f) That is, if all elements in either stream match, then all elements in the combined stream should also match. If you decide that forAll returns false for the empty stream, that property no longer holds.
I haven't seen your implementation of hasSubsequence, but the one given in the answers uses exists rather than forAll. We could rewrite it using forAll by using a double negation:
def hasSubsequence[A](s: Stream[A]): Boolean =
!(tails forAll (a => !(a startsWith s)))
