Skip to content

Commit 79fad83

Browse files
committed
Merge pull request #23 from MichaelXavier/writer-misc
Add execWriterT
2 parents d7eccba + 2c45993 commit 79fad83

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

docs/Module.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@
667667

668668
### Values
669669

670-
evalStateT :: forall s m a. (Monad m) => StateT s m a -> s -> m a
670+
evalStateT :: forall s m a. (Apply m) => StateT s m a -> s -> m a
671671

672-
execStateT :: forall s m a. (Monad m) => StateT s m a -> s -> m s
672+
execStateT :: forall s m a. (Apply m) => StateT s m a -> s -> m s
673673

674674
liftCallCCState :: forall s m a b. (((Tuple a s -> m (Tuple b s)) -> m (Tuple a s)) -> m (Tuple a s)) -> ((a -> StateT s m b) -> StateT s m a) -> StateT s m a
675675

@@ -779,6 +779,8 @@
779779

780780
### Values
781781

782+
execWriterT :: forall w m a. (Apply m) => WriterT w m a -> m w
783+
782784
liftCallCCWriter :: forall w m a b. (Monoid w) => (((Tuple a w -> m (Tuple b w)) -> m (Tuple a w)) -> m (Tuple a w)) -> ((a -> WriterT w m b) -> WriterT w m a) -> WriterT w m a
783785

784786
liftCatchWriter :: forall w m e a. (m (Tuple a w) -> (e -> m (Tuple a w)) -> m (Tuple a w)) -> WriterT w m a -> (e -> WriterT w m a) -> WriterT w m a

src/Control/Monad/State/Trans.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ newtype StateT s m a = StateT (s -> m (Tuple a s))
1313
runStateT :: forall s m a. StateT s m a -> s -> m (Tuple a s)
1414
runStateT (StateT s) = s
1515

16-
evalStateT :: forall s m a. (Monad m) => StateT s m a -> s -> m a
17-
evalStateT m s = runStateT m s >>= \(Tuple x _) -> return x
16+
evalStateT :: forall s m a. (Apply m) => StateT s m a -> s -> m a
17+
evalStateT m s = fst <$> runStateT m s
1818

19-
execStateT :: forall s m a. (Monad m) => StateT s m a -> s -> m s
20-
execStateT m s = runStateT m s >>= \(Tuple _ s) -> return s
19+
execStateT :: forall s m a. (Apply m) => StateT s m a -> s -> m s
20+
execStateT m s = snd <$> runStateT m s
2121

2222
mapStateT :: forall s m1 m2 a b. (m1 (Tuple a s) -> m2 (Tuple b s)) -> StateT s m1 a -> StateT s m2 b
2323
mapStateT f m = StateT $ f <<< runStateT m

src/Control/Monad/Writer/Trans.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ newtype WriterT w m a = WriterT (m (Tuple a w))
1313
runWriterT :: forall w m a. WriterT w m a -> m (Tuple a w)
1414
runWriterT (WriterT x) = x
1515

16+
execWriterT :: forall w m a. (Apply m) => WriterT w m a -> m w
17+
execWriterT m = snd <$> runWriterT m
18+
1619
mapWriterT :: forall w1 w2 m1 m2 a b. (m1 (Tuple a w1) -> m2 (Tuple b w2)) -> WriterT w1 m1 a -> WriterT w2 m2 b
1720
mapWriterT f m = WriterT $ f (runWriterT m)
1821

0 commit comments

Comments
 (0)