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.

Articles by others on the same topic (0)

There are currently no matching articles.