@@ -2,13 +2,19 @@ module Data.Const where
2
2
3
3
import Prelude
4
4
5
+ import Data.Bifoldable (class Bifoldable )
6
+ import Data.Bifunctor (class Bifunctor )
7
+ import Data.Bitraversable (class Bitraversable )
5
8
import Data.Eq (class Eq1 )
6
9
import Data.Foldable (class Foldable )
10
+ import Data.FoldableWithIndex (class FoldableWithIndex )
7
11
import Data.Functor.Contravariant (class Contravariant )
8
12
import Data.Functor.Invariant (class Invariant , imapF )
13
+ import Data.FunctorWithIndex (class FunctorWithIndex )
9
14
import Data.Newtype (class Newtype )
10
15
import Data.Ord (class Ord1 )
11
16
import Data.Traversable (class Traversable )
17
+ import Data.TraversableWithIndex (class TraversableWithIndex )
12
18
13
19
-- | The `Const` type constructor, which wraps its first type argument
14
20
-- | and ignores its second. That is, `Const a b` is isomorphic to `a`
@@ -55,6 +61,12 @@ derive newtype instance booleanAlgebraConst :: BooleanAlgebra a => BooleanAlgebr
55
61
56
62
derive instance functorConst :: Functor (Const a )
57
63
64
+ instance bifunctorConst :: Bifunctor Const where
65
+ bimap f _ (Const a) = Const (f a)
66
+
67
+ instance functorWithIndexConst :: FunctorWithIndex Void (Const a ) where
68
+ mapWithIndex _ (Const x) = Const x
69
+
58
70
instance invariantConst :: Invariant (Const a ) where
59
71
imap = imapF
60
72
@@ -72,6 +84,23 @@ instance foldableConst :: Foldable (Const a) where
72
84
foldl _ z _ = z
73
85
foldMap _ _ = mempty
74
86
87
+ instance foldableWithIndexConst :: FoldableWithIndex Void (Const a ) where
88
+ foldrWithIndex _ z _ = z
89
+ foldlWithIndex _ z _ = z
90
+ foldMapWithIndex _ _ = mempty
91
+
92
+ instance bifoldableConst :: Bifoldable Const where
93
+ bifoldr f _ z (Const a) = f a z
94
+ bifoldl f _ z (Const a) = f z a
95
+ bifoldMap f _ (Const a) = f a
96
+
75
97
instance traversableConst :: Traversable (Const a ) where
76
98
traverse _ (Const x) = pure (Const x)
77
99
sequence (Const x) = pure (Const x)
100
+
101
+ instance traversableWithIndexConst :: TraversableWithIndex Void (Const a ) where
102
+ traverseWithIndex _ (Const x) = pure (Const x)
103
+
104
+ instance bitraversableConst :: Bitraversable Const where
105
+ bitraverse f _ (Const a) = Const <$> f a
106
+ bisequence (Const a) = Const <$> a
0 commit comments