Open aaditmshah opened 8 months ago
Just like Biapplicative
, we can define a generic function to traverse a Traversable
container in a Bialternative
.
traverseLeft :: (Traversable t, Bialternative p) => (a -> p b c) -> t a -> p (t b) c
traverseLeft f = go . traverse (One . f)
where
go :: Bialternative p => Mag (p a b) a x -> p x b
go (Pure t) = left t
go (Map f xs) = first f (go xs)
go (Ap fs xs) = go fs <<|>> go xs
#if MIN_VERSION_base(4,10,0)
go (LiftA2 f xs ys) = liftL2 f (go xs) (go ys)
#endif
go (One p) = p
This uses the same data type Mag
that's defined in Data.Biapplicative
.
Bialternative
is for bifunctors likeEither
.For example, here's the
Bialternative
instance ofEither
.Instances of
Bialternative
should satisfy the following laws.