Added a foldM1 function to the Utils module

This commit is contained in:
Neil Brown 2009-04-08 15:33:36 +00:00
parent 009cf8cc8b
commit d2fb80c516

View File

@ -393,3 +393,8 @@ liftWrapStateT wrap m
(x, st') <- lift $ wrap (runStateT m st)
put st'
return x
-- The foldM equivalent of foldl1:
foldM1 :: Monad m => (a -> a -> m a) -> [a] -> m a
foldM1 f (x:xs) = foldM f x xs
foldM1 _ [] = fail "Empty list in foldM1"