1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Generalize coalesceBy to Both (Coalesce a).

This commit is contained in:
Rob Rix 2016-03-07 14:32:31 -05:00
parent 767a9e93fc
commit 6dfb8524ff

View File

@ -55,10 +55,10 @@ instance Monoid a => Monoid (Both a) where
mappend a b = mappend <$> a <*> b
instance (PartialSemigroup a, Monoid a) => PartialSemigroup (Both a) where
coalesce = coalesceBy coalesce
coalesce = coalesceBy (pure coalesce)
coalesceBy :: Monoid a => Coalesce a -> Both a -> Both a -> Maybe (Both a)
coalesceBy coalesce a b = case coalesce <$> a <*> b of
coalesceBy :: Monoid a => Both (Coalesce a) -> Both a -> Both a -> Maybe (Both a)
coalesceBy coalesce a b = case coalesce <*> a <*> b of
Both (Just l, Just r) -> Just (both l r)
Both (Nothing, Just r) -> Just (both (fst a `mappend` fst b) r)
Both (Just l, Nothing) -> Just (both l (snd a `mappend` snd b))