-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Break from a loop -- @package break @version 1.0.0 -- | Example usage: -- --
-- import Control.Break -- import Control.Monad.State -- import Prelude hiding (break) -- -- example :: State Int () -- example = loop (do -- n <- lift get -- Inside a `loop`, wrap commands in `lift` -- if n < 10 -- then lift (put (n + 1)) -- You keep looping by default -- else break () ) -- Use `break` to exit from the `loop` ---- -- The loop command runs the given command repeatedly until the -- command breaks from the loop using break: -- --
-- >>> execState example 0 -- 10 ---- -- For some effects (like State), you can omit lift: -- --
-- example :: State Int () -- example = loop (do -- n <- get -- if n < 10 -- then put (n + 1) -- else break () ) ---- -- The loop will return whatever value you supply to break: -- --
-- example :: State Int Bool -- example = loop (do -- n <- get -- if n < 10 -- then put (n + 1) -- else break True ) ---- --
-- >>> runState example 0 -- (True,10) --module Control.Break -- | For the most common use cases you will: -- -- data Break r m a -- | (loop m) runs the action 'm' repeatedly until you -- break from the loop loop :: Monad m => Break r m () -> m r -- | break from a loop -- -- The argument you supply to break is the return value of the -- loop break :: Monad m => r -> Break r m a -- | Lift a computation from the argument monad to the constructed monad. lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a instance Functor m => Functor (Break r m) instance (Monad m, Functor m) => Applicative (Break r m) instance Monad m => Monad (Break r m) instance MonadTrans (Break r) instance MonadIO m => MonadIO (Break r m) instance MonadCont m => MonadCont (Break r m) instance MonadState s m => MonadState s (Break r m) instance MonadWriter w m => MonadWriter w (Break r m)