Skip to content

Commit 1b7938a

Browse files
authored
Merge pull request #17 from MonoidMusician/master
Traversable1 and TraversableWithIndex
2 parents 04caa3d + b75db9a commit 1b7938a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Data/Identity.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import Control.Extend (class Extend)
88
import Control.Lazy (class Lazy)
99
import Data.Eq (class Eq1)
1010
import Data.Foldable (class Foldable)
11+
import Data.FoldableWithIndex (class FoldableWithIndex)
1112
import Data.Functor.Invariant (class Invariant, imapF)
13+
import Data.FunctorWithIndex (class FunctorWithIndex)
1214
import Data.Newtype (class Newtype)
1315
import Data.Ord (class Ord1)
16+
import Data.Semigroup.Foldable (class Foldable1)
17+
import Data.Semigroup.Traversable (class Traversable1)
1418
import Data.Traversable (class Traversable)
19+
import Data.TraversableWithIndex (class TraversableWithIndex)
1520

1621
newtype Identity a = Identity a
1722

@@ -50,6 +55,9 @@ derive instance ord1Identity :: Ord1 Identity
5055

5156
derive instance functorIdentity :: Functor Identity
5257

58+
instance functorWithIndexIdentity :: FunctorWithIndex Unit Identity where
59+
mapWithIndex f (Identity a) = Identity (f unit a)
60+
5361
instance 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+
8198
instance 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

Comments
 (0)