implemented takeWhile using unfold.