mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Add a Monoid instance for Adjoined over partial semigroups.
This commit is contained in:
parent
42579d9c5b
commit
d54324e20c
@ -1,6 +1,8 @@
|
|||||||
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
|
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
|
||||||
module Data.Adjoined where
|
module Data.Adjoined where
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
newtype Adjoined a = Adjoined { unAdjoined :: Maybe a }
|
newtype Adjoined a = Adjoined { unAdjoined :: Maybe a }
|
||||||
deriving (Eq, Foldable, Functor, Show, Traversable)
|
deriving (Eq, Foldable, Functor, Show, Traversable)
|
||||||
|
|
||||||
@ -17,3 +19,7 @@ instance Applicative Adjoined where
|
|||||||
instance Monad Adjoined where
|
instance Monad Adjoined where
|
||||||
return = pure
|
return = pure
|
||||||
Adjoined a >>= f = Adjoined $ a >>= unAdjoined . f
|
Adjoined a >>= f = Adjoined $ a >>= unAdjoined . f
|
||||||
|
|
||||||
|
instance PartialSemigroup a => Monoid (Adjoined a) where
|
||||||
|
mempty = Adjoined Nothing
|
||||||
|
mappend (Adjoined a) (Adjoined b) = Adjoined . join $ coalesce <$> a <*> b
|
||||||
|
Loading…
Reference in New Issue
Block a user