Skip to content

[RFC] foldWhile  #453

@ocramz

Description

@ocramz

A specialized version of mapAccumWhile that keeps folding as long as the function argument returns 'Right'

foldWhile :: (Monad m) => (a -> s -> Either s s) -> s -> C.ConduitT a o m s
foldWhile f = loop
  where
    loop !s = C.await >>= maybe (pure s) go
      where
        go a = either (return $!) loop $ f a s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions