takeWhile implemented using lazy version of foldRight