Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Created January 15, 2014 20:31
Show Gist options
  • Select an option

  • Save joshrotenberg/8443959 to your computer and use it in GitHub Desktop.

Select an option

Save joshrotenberg/8443959 to your computer and use it in GitHub Desktop.
From http://hackage.haskell.org/package/hylolib-1.4.0/docs/src/HyLo-Util.html, modified slightly to not return the final item in the list
sequenceUntil :: Monad m => (a -> Bool) -> [m a] -> m [a]
sequenceUntil _ [] = return []
sequenceUntil p (m:ms) = do a <- m
if p a
then return $ init [a]
else do as <- sequenceUntil p ms
return (a:as)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment