Skip to content

Commit e5b8bb6

Browse files
committed
Add Functor, Foldable, Traversable too
1 parent 6021635 commit e5b8bb6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Data/Lens/Internal/Tagged.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import Prelude
55

66
import Data.Either (Either(..))
77
import Data.Eq (class Eq1)
8+
import Data.Foldable (class Foldable)
89
import Data.Newtype (class Newtype)
910
import Data.Ord (class Ord1)
1011
import Data.Profunctor (class Profunctor)
1112
import Data.Profunctor.Choice (class Choice)
1213
import Data.Profunctor.Closed (class Closed)
1314
import Data.Profunctor.Costrong (class Costrong)
15+
import Data.Traversable (class Traversable)
1416
import Data.Tuple (Tuple(..))
1517

1618
newtype Tagged a b = Tagged b
@@ -23,6 +25,8 @@ instance eq1Tagged :: Eq1 (Tagged a) where eq1 = eq
2325
derive instance ordTagged :: Ord b => Ord (Tagged a b)
2426
instance ord1Tagged :: Ord1 (Tagged a) where compare1 = compare
2527

28+
derive instance functorTagged :: Functor (Tagged a)
29+
2630
instance taggedProfunctor :: Profunctor Tagged where
2731
dimap _ g (Tagged x) = Tagged (g x)
2832

@@ -36,3 +40,12 @@ instance taggedCostrong :: Costrong Tagged where
3640

3741
instance taggedClosed :: Closed Tagged where
3842
closed (Tagged b) = Tagged (const b)
43+
44+
instance foldableTagged :: Foldable (Tagged a) where
45+
foldMap f (Tagged a) = f a
46+
foldr f b (Tagged a) = f a b
47+
foldl f b (Tagged a) = f b a
48+
49+
instance traversableTagged :: Traversable (Tagged a) where
50+
sequence (Tagged a) = map Tagged a
51+
traverse f (Tagged a) = map Tagged (f a)

0 commit comments

Comments
 (0)