List unfold (source code)

= List unfold
{title2=`unfoldr :: (s -> Maybe (a,s)) -> s -> [a]`}

Generate a <list> from a state: a step returning `Nothing` terminates; `Just (x,s')` emits `x` and continues from `s'`. Thus `unfoldr step s = case step s of Nothing -> []; Just (x,s') -> x : unfoldr step s'`. A <list unfold> decomposes the evolving state, whereas a <list fold> consumes existing constructors. <Productivity> depends on each demanded constructor becoming available, not merely on using <lazy evaluation>.