mirror of
https://github.com/github/semantic.git
synced 2024-12-19 21:01:35 +03:00
Define a helper to construct an Edit from a pair of Maybes.
This commit is contained in:
parent
cb3fa623b1
commit
fc93bb4b4d
@ -3,9 +3,10 @@ module Data.Edit
|
||||
( Edit(..)
|
||||
, edit
|
||||
, mergeEdit
|
||||
, fromMaybes
|
||||
) where
|
||||
|
||||
import Control.Applicative (liftA2)
|
||||
import Control.Applicative ((<|>), liftA2)
|
||||
import Data.Bifoldable
|
||||
import Data.Bifunctor
|
||||
import Data.Bitraversable
|
||||
@ -31,6 +32,9 @@ edit delete insert compare = \case
|
||||
mergeEdit :: (a -> a -> a) -> Edit a a -> a
|
||||
mergeEdit = edit id id
|
||||
|
||||
fromMaybes :: Maybe a -> Maybe b -> Maybe (Edit a b)
|
||||
fromMaybes a b = liftA2 Compare a b <|> Delete <$> a <|> Insert <$> b
|
||||
|
||||
|
||||
instance Bifunctor Edit where
|
||||
bimap = bimapDefault
|
||||
|
Loading…
Reference in New Issue
Block a user