Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/functional-programming-design-and-analysis-of-algorithms-resit/4/c/solution

The required function composition is
unfold p f g = map f . takeWhile (not . p) . iterate g
iterate g supplies the successive states, takeWhile (not . p) retains precisely those before the first stopping state, and map f produces their outputs. If the initial state satisfies the stopping predicate, both sides return the empty list. Otherwise both emit the same head and repeat from g x; the same argument applies to every demanded finite prefix of an infinite result.

New to topics? Read the docs here!