Commit ce4d235c authored by Steffen Michels's avatar Steffen Michels

Merge branch 'mapStM' into 'master'

Add mapStM, a combination of mapM and mapSt

See merge request !237
parents 43ce96d5 6bb43811
Pipeline #17547 passed with stage
in 3 minutes and 13 seconds
......@@ -37,6 +37,7 @@ forever :: !(a b) -> a c | Monad a
join :: !(a (a b)) -> a b | Monad a
zipWithM :: (.a -> .(.b -> c d)) ![.a] [.b] -> c [d] | Monad c
foldM :: (a -> .(b -> c a)) a ![b] -> c a | Monad c
mapStM :: (a st -> m (b, st)) ![a] !st -> m (![b], st) | Monad m
replicateM :: !.Int (a b) -> a [b] | Monad a
(>=>) infixr 1 :: u:(.a -> b c) (c -> b d) -> v:(.a -> b d) | Monad b, [v <= u]
(<=<) infixr 1 :: u:((a -> b c) -> v:(w:(.d -> b a) -> x:(.d -> b c))) | Monad b, [v <= u,x <= w]
......
......@@ -40,6 +40,10 @@ foldM :: (a -> .(b -> c a)) a ![b] -> c a | Monad c
foldM _ a [] = lift a
foldM f a [x:xs] = f a x >>= \fax -> foldM f fax xs
mapStM :: (a st -> m (b, st)) ![a] !st -> m (![b], st) | Monad m
mapStM _ [] st = pure ([], st)
mapStM f [x:xs] st = f x st >>= \(y,st) -> mapStM f xs st >>= \(ys,st) -> pure ([y:ys],st)
replicateM :: !.Int (a b) -> a [b] | Monad a
replicateM n x = sequence (replicate n x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment