@@ -217,9 +217,7 @@ filter isOdd naturals
217filter isOdd twos
217filter isOdd twos
220−The produced Stream can go into an infinite loop if no more elements
221−satisfy the predicate. So be sure that there are infinitely many terms
222−in the stream that satisfy the predicate.
220+This can infinite loop if no more elements in the stream satisfy the predicate!
224filter : (a -> Bool) -> Stream a -> Stream a
222filter : (a -> Bool) -> Stream a -> Stream a
225filter pred xs = cons' <| (\() ->
223filter pred xs = cons' <| (\() ->
@@ -237,12 +235,13 @@ takeWhile (\n -> n < 10) powersOf2 == [2,4,8]
237-- Bad! Infinite loop!
235-- Bad! Infinite loop!
238takeWhile isEven powersOf2
236takeWhile isEven powersOf2
239+This can infinite loop if all elements of the stream satisfy the predicate!
241takeWhile : (a -> Bool) -> Stream a -> [a]
241takeWhile : (a -> Bool) -> Stream a -> [a]
242takeWhile pred xs = fst <| splitWith pred xs
242takeWhile pred xs = fst <| splitWith pred xs
244{-| Drop values from the stream as long as the predicate holds.
244{-| Drop values from the stream as long as the predicate holds.
245−This can infinite loop if all elements of the stream satisfy the predicate!
247```haskell
246```haskell
248-- 16, 32, 64, 128, ...
247-- 16, 32, 64, 128, ...
@@ -251,15 +250,22 @@ dropWhile (\n -> n < 10) powersOf2
251-- Bad! Infinite loop!
250-- Bad! Infinite loop!
252dropWhile isEven powersOf2
251dropWhile isEven powersOf2
254+This can infinite loop if all elements of the stream satisfy the predicate!
255dropWhile : (a -> Bool) -> Stream a -> Stream a
256dropWhile : (a -> Bool) -> Stream a -> Stream a
256dropWhile pred xs = snd <| splitWith pred xs
257dropWhile pred xs = snd <| splitWith pred xs
258−{-| Split a stream when a predicate holds and
259+{-| Combination of `takeWhile` and `dropWhile`. Split a stream when
259−the rest of the Stream. This function only terminates if there is
260+the predicate no longer holds.
260−an element of the stream for which the predicate does not hold.
261+
263+splitWith pred xs == (takeWhile pred xs, dropWhile pred xs)
265+splitWith (\n -> n < 10) powersOf2 == ([2,4,8], ...)
262− splitWith pred xs == (takeWhile pred xs, dropWhile pred xs)
268+This can infinite loop if all elements satisfy the predicate!
264splitWith : (a -> Bool) -> Stream a -> ([a], Stream a)
270splitWith : (a -> Bool) -> Stream a -> ([a], Stream a)
265splitWith pred xs = let (hd, tl) = unS xs in
271splitWith pred xs = let (hd, tl) = unS xs in