Skip to content

Commit bc5db27

Browse files
authored
Merge pull request #12 from MonoidMusician/master
(Bi)Traversable(WithIndex) and friends
2 parents f613785 + 0df1492 commit bc5db27

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Data/Const.purs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ module Data.Const where
22

33
import Prelude
44

5+
import Data.Bifoldable (class Bifoldable)
6+
import Data.Bifunctor (class Bifunctor)
7+
import Data.Bitraversable (class Bitraversable)
58
import Data.Eq (class Eq1)
69
import Data.Foldable (class Foldable)
10+
import Data.FoldableWithIndex (class FoldableWithIndex)
711
import Data.Functor.Contravariant (class Contravariant)
812
import Data.Functor.Invariant (class Invariant, imapF)
13+
import Data.FunctorWithIndex (class FunctorWithIndex)
914
import Data.Newtype (class Newtype)
1015
import Data.Ord (class Ord1)
1116
import Data.Traversable (class Traversable)
17+
import Data.TraversableWithIndex (class TraversableWithIndex)
1218

1319
-- | The `Const` type constructor, which wraps its first type argument
1420
-- | and ignores its second. That is, `Const a b` is isomorphic to `a`
@@ -55,6 +61,12 @@ derive newtype instance booleanAlgebraConst :: BooleanAlgebra a => BooleanAlgebr
5561

5662
derive instance functorConst :: Functor (Const a)
5763

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+
5870
instance invariantConst :: Invariant (Const a) where
5971
imap = imapF
6072

@@ -72,6 +84,23 @@ instance foldableConst :: Foldable (Const a) where
7284
foldl _ z _ = z
7385
foldMap _ _ = mempty
7486

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+
7597
instance traversableConst :: Traversable (Const a) where
7698
traverse _ (Const x) = pure (Const x)
7799
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

Comments
 (0)