@@ -8,10 +8,15 @@ import Control.Extend (class Extend)
88import Control.Lazy (class Lazy )
99import Data.Eq (class Eq1 )
1010import Data.Foldable (class Foldable )
11+ import Data.FoldableWithIndex (class FoldableWithIndex )
1112import Data.Functor.Invariant (class Invariant , imapF )
13+ import Data.FunctorWithIndex (class FunctorWithIndex )
1214import Data.Newtype (class Newtype )
1315import Data.Ord (class Ord1 )
16+ import Data.Semigroup.Foldable (class Foldable1 )
17+ import Data.Semigroup.Traversable (class Traversable1 )
1418import Data.Traversable (class Traversable )
19+ import Data.TraversableWithIndex (class TraversableWithIndex )
1520
1621newtype Identity a = Identity a
1722
@@ -50,6 +55,9 @@ derive instance ord1Identity :: Ord1 Identity
5055
5156derive instance functorIdentity :: Functor Identity
5257
58+ instance functorWithIndexIdentity :: FunctorWithIndex Unit Identity where
59+ mapWithIndex f (Identity a) = Identity (f unit a)
60+
5361instance invariantIdentity :: Invariant Identity where
5462 imap = imapF
5563
@@ -78,6 +86,22 @@ instance foldableIdentity :: Foldable Identity where
7886 foldl f z (Identity x) = f z x
7987 foldMap f (Identity x) = f x
8088
89+ instance foldable1Identity :: Foldable1 Identity where
90+ fold1 (Identity x) = x
91+ foldMap1 f (Identity x) = f x
92+
93+ instance foldableWithIndexIdentity :: FoldableWithIndex Unit Identity where
94+ foldrWithIndex f z (Identity x) = f unit x z
95+ foldlWithIndex f z (Identity x) = f unit z x
96+ foldMapWithIndex f (Identity x) = f unit x
97+
8198instance traversableIdentity :: Traversable Identity where
8299 traverse f (Identity x) = Identity <$> f x
83100 sequence (Identity x) = Identity <$> x
101+
102+ instance traversable1Identity :: Traversable1 Identity where
103+ traverse1 f (Identity x) = Identity <$> f x
104+ sequence1 (Identity x) = Identity <$> x
105+
106+ instance traversableWithIndexIdentity :: TraversableWithIndex Unit Identity where
107+ traverseWithIndex f (Identity x) = Identity <$> f unit x
0 commit comments