Skip to content

Which unfoldM is meant in "unfoldM uncons gives the [t] corresponding to the stream"? #144

@johannes-riecken

Description

@johannes-riecken

The documentation for Stream mentions "unfoldM uncons gives the [t] corresponding to the stream", but unfoldM doesn't exist in base or parsec package. I assume the monadification of Data.List's unfoldr is meant if evaluated in the identity monad? Then maybe this would be a better documentation:

unfoldM uncons gives the [t] corresponding to the stream if the result type is the Identity monad and unfoldM is defined as follows:
unfoldM :: Monad m => (a -> m (Maybe (b, a))) -> a -> m [b]
unfoldM f b = do
    fb <- f b
    case fb of
        Just (a, b') -> pure ((:) a) <*> unfoldM f b'
        Nothing -> pure []

Or maybe change it to "unfoldr (runIdentity . uncons) gives the [t] corresponding to the stream"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions