Skip to content

Commit 6c8814c

Browse files
committed
Add Crosswalk instance for These1
1 parent 52f821d commit 6c8814c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

semialign/src/Data/Crosswalk.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Data.Functor.Compose (Compose (..))
1717
import Data.Functor.Const (Const (..))
1818
import Data.Functor.Identity (Identity (..))
1919
import Data.Functor.Sum (Sum (..))
20+
import Data.Functor.These (These1 (..))
2021
import Data.Proxy (Proxy (..))
2122
import Data.Traversable (Traversable (traverse))
2223
import Data.Vector.Generic (Vector)
@@ -107,6 +108,12 @@ instance (Crosswalk f, Crosswalk g) => Crosswalk (Sum f g) where
107108
crosswalk f (InL xs) = InL <$> crosswalk f xs
108109
crosswalk f (InR xs) = InR <$> crosswalk f xs
109110

111+
instance (Crosswalk f, Crosswalk g) => Crosswalk (These1 f g) where
112+
crosswalk f (This1 xs) = This1 <$> crosswalk f xs
113+
crosswalk f (That1 ys) = That1 <$> crosswalk f ys
114+
crosswalk f (These1 xs ys) = alignWith go (crosswalk f xs) (crosswalk f ys)
115+
where go = these This1 That1 These1
116+
110117
instance (Crosswalk f, Crosswalk g) => Crosswalk (Compose f g) where
111118
crosswalk f
112119
= fmap Compose -- can't coerce: maybe the Align-able thing has role nominal

these-tests/test/Tests/Crosswalk.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Data.Functor.Compose (Compose (..))
1212
import Data.Functor.Const (Const)
1313
import Data.Functor.Identity (Identity (..))
1414
import Data.Functor.Sum (Sum)
15+
import Data.Functor.These (These1)
1516
import Data.List.NonEmpty (NonEmpty)
1617
import Data.Map (Map)
1718
import Data.Proxy (Proxy)
@@ -53,6 +54,7 @@ crosswalkProps = testGroup "Crosswalk"
5354
, crosswalkLaws (P :: P Proxy)
5455
, crosswalkLaws (P :: P (Const Int))
5556
, crosswalkLaws (P :: P (Sum [] []))
57+
, crosswalkLaws (P :: P (These1 [] []))
5658
, crosswalkLaws (P :: P (Compose [] []))
5759
, crosswalkLaws (P :: P (MaybeT []))
5860
]

0 commit comments

Comments
 (0)