= Solution
Generate the successive states using the <Haskell iterate function>, keep those before the stopping test becomes true using the <Haskell takeWhile function>, then map the output function:
``
unfoldU :: (s -> Bool) -> (s -> a) -> (s -> s) -> s -> [a]
unfoldU p f g = map f . takeWhile (not . p) . iterate g
``
The missing expression is therefore $\boxed{\operatorname{takeWhile}(\operatorname{not}\circ p)\circ\operatorname{iterate}(g)}$. On states $x,g(x),g^2(x),\ldots$, the first state satisfying `p` is excluded, just as in the recursive <list unfold>. If no state satisfies `p`, the result is an infinite <lazy list>, provided each demanded test, output and transition terminates.
Back to article page