11-- | This module defines the `Tagged` profunctor
22module Data.Lens.Internal.Tagged where
33
4+ import Prelude
5+
46import Data.Either (Either (..))
5- import Data.Function (const )
7+ import Data.Eq (class Eq1 )
8+ import Data.Foldable (class Foldable )
69import Data.Newtype (class Newtype )
10+ import Data.Ord (class Ord1 )
711import Data.Profunctor (class Profunctor )
812import Data.Profunctor.Choice (class Choice )
913import Data.Profunctor.Closed (class Closed )
1014import Data.Profunctor.Costrong (class Costrong )
15+ import Data.Traversable (class Traversable )
1116import Data.Tuple (Tuple (..))
1217
1318newtype Tagged a b = Tagged b
1419
1520derive instance newtypeTagged :: Newtype (Tagged a b ) _
1621
22+ derive instance eqTagged :: Eq b => Eq (Tagged a b )
23+ instance eq1Tagged :: Eq1 (Tagged a ) where eq1 = eq
24+
25+ derive instance ordTagged :: Ord b => Ord (Tagged a b )
26+ instance ord1Tagged :: Ord1 (Tagged a ) where compare1 = compare
27+
28+ derive instance functorTagged :: Functor (Tagged a )
29+
1730instance taggedProfunctor :: Profunctor Tagged where
1831 dimap _ g (Tagged x) = Tagged (g x)
1932
@@ -27,3 +40,12 @@ instance taggedCostrong :: Costrong Tagged where
2740
2841instance taggedClosed :: Closed Tagged where
2942 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