1
1
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:
Rob Rix 2019-10-18 12:24:44 -04:00
parent cb3fa623b1
commit fc93bb4b4d
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -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