Skip to content

Commit d093f3b

Browse files
authored
Merge pull request #78 from purescript-contrib/tagged-eq-ord
Add extra instances for `Tagged`
2 parents ab3727d + e5b8bb6 commit d093f3b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Data/Lens/Internal/Tagged.purs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
-- | This module defines the `Tagged` profunctor
22
module Data.Lens.Internal.Tagged where
33

4+
import Prelude
5+
46
import Data.Either (Either(..))
5-
import Data.Function (const)
7+
import Data.Eq (class Eq1)
8+
import Data.Foldable (class Foldable)
69
import Data.Newtype (class Newtype)
10+
import Data.Ord (class Ord1)
711
import Data.Profunctor (class Profunctor)
812
import Data.Profunctor.Choice (class Choice)
913
import Data.Profunctor.Closed (class Closed)
1014
import Data.Profunctor.Costrong (class Costrong)
15+
import Data.Traversable (class Traversable)
1116
import Data.Tuple (Tuple(..))
1217

1318
newtype Tagged a b = Tagged b
1419

1520
derive 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+
1730
instance taggedProfunctor :: Profunctor Tagged where
1831
dimap _ g (Tagged x) = Tagged (g x)
1932

@@ -27,3 +40,12 @@ instance taggedCostrong :: Costrong Tagged where
2740

2841
instance 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

Comments
 (0)