monad-loops icon indicating copy to clipboard operation
monad-loops copied to clipboard

Provide breakable loops

Open singpolyma opened this issue 12 years ago • 1 comments

This can be done with EitherT or EitherRT (or similar internal functionality) :

loop f = runEitherT (forever f) >>= (\(Left x) -> return x)

break = left

singpolyma avatar Jan 25 '13 15:01 singpolyma

For this purpose I actually really liked the "loop-while" library on Hackage - it appears not to build any more, but as simple as it is I suspect it just needs its dependency versions loosened. It provides a very nice monad transformer (LoopWhileT) that does exactly this, and gives more informative types while it's at it. The newer loops package looks more complex but is probably also a good alternative.

mokus0 avatar May 01 '16 21:05 mokus0