Skip to content

Commit 41d6303

Browse files
cryogeniangaryb
authored andcommitted
EnvT - Traversable (#104)
* EnvT - Traversable * fixed typo
1 parent 1b16d8b commit 41d6303

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Control/Comonad/Env/Trans.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Control.Comonad (class Comonad, extract)
88
import Control.Comonad.Trans.Class (class ComonadTrans)
99
import Control.Extend (class Extend, (<<=))
1010

11+
import Data.Traversable (class Traversable, class Foldable, foldl, foldr, foldMap, traverse, sequence)
1112
import Data.Tuple (Tuple(..))
1213
import Data.Newtype (class Newtype)
1314

@@ -44,3 +45,12 @@ instance comonadEnvT :: Comonad w => Comonad (EnvT e w) where
4445

4546
instance comonadTransEnvT :: ComonadTrans (EnvT e) where
4647
lower (EnvT (Tuple e x)) = x
48+
49+
instance foldableEnvT :: Foldable f => Foldable (EnvT e f) where
50+
foldl fn a (EnvT (Tuple _ x)) = foldl fn a x
51+
foldr fn a (EnvT (Tuple _ x)) = foldr fn a x
52+
foldMap fn (EnvT (Tuple _ x)) = foldMap fn x
53+
54+
instance traversableEnvT :: Traversable f => Traversable (EnvT e f) where
55+
sequence (EnvT (Tuple a x)) = EnvT <$> Tuple a <$> sequence x
56+
traverse f (EnvT (Tuple a x)) = EnvT <$> Tuple a <$> traverse f x

0 commit comments

Comments
 (0)