@@ -8,10 +8,15 @@ import Control.Extend (class Extend)
8
8
import Control.Lazy (class Lazy )
9
9
import Data.Eq (class Eq1 )
10
10
import Data.Foldable (class Foldable )
11
+ import Data.FoldableWithIndex (class FoldableWithIndex )
11
12
import Data.Functor.Invariant (class Invariant , imapF )
13
+ import Data.FunctorWithIndex (class FunctorWithIndex )
12
14
import Data.Newtype (class Newtype )
13
15
import Data.Ord (class Ord1 )
16
+ import Data.Semigroup.Foldable (class Foldable1 )
17
+ import Data.Semigroup.Traversable (class Traversable1 )
14
18
import Data.Traversable (class Traversable )
19
+ import Data.TraversableWithIndex (class TraversableWithIndex )
15
20
16
21
newtype Identity a = Identity a
17
22
@@ -50,6 +55,9 @@ derive instance ord1Identity :: Ord1 Identity
50
55
51
56
derive instance functorIdentity :: Functor Identity
52
57
58
+ instance functorWithIndexIdentity :: FunctorWithIndex Unit Identity where
59
+ mapWithIndex f (Identity a) = Identity (f unit a)
60
+
53
61
instance invariantIdentity :: Invariant Identity where
54
62
imap = imapF
55
63
@@ -78,6 +86,22 @@ instance foldableIdentity :: Foldable Identity where
78
86
foldl f z (Identity x) = f z x
79
87
foldMap f (Identity x) = f x
80
88
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
+
81
98
instance traversableIdentity :: Traversable Identity where
82
99
traverse f (Identity x) = Identity <$> f x
83
100
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