Skip to content

Commit a216a66

Browse files
committed
Call it PatchOrReplacement instead of Patchable
1 parent 924a391 commit a216a66

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed

patch.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ library
5757
, Data.Patch.Map
5858
, Data.Patch.MapWithMove
5959
, Data.Patch.MapWithPatchingMove
60-
, Data.Patch.Patchable
60+
, Data.Patch.PatchOrReplacement
6161
, Data.Semigroup.Additive
6262

6363
ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs

src/Data/Patch/PatchOrReplacement.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE FlexibleContexts #-}
4+
{-# LANGUAGE FlexibleInstances #-}
5+
{-# LANGUAGE LambdaCase #-}
6+
{-# LANGUAGE StandaloneDeriving #-}
7+
{-# LANGUAGE UndecidableInstances #-}
8+
9+
module Data.Patch.PatchOrReplacement where
10+
11+
import Data.Patch
12+
#if !MIN_VERSION_base(4,11,0)
13+
import Data.Semigroup (Semigroup (..))
14+
#endif
15+
import GHC.Generics
16+
17+
-- | Like SemiMap/PartialMap but for anything patchable
18+
data PatchOrReplacement p
19+
= PatchOrReplacement_Patch p
20+
| PatchOrReplacement_Complete (PatchTarget p)
21+
deriving (Generic)
22+
23+
deriving instance (Eq p, Eq (PatchTarget p)) => Eq (PatchOrReplacement p)
24+
deriving instance (Ord p, Ord (PatchTarget p)) => Ord (PatchOrReplacement p)
25+
deriving instance (Show p, Show (PatchTarget p)) => Show (PatchOrReplacement p)
26+
deriving instance (Read p, Read (PatchTarget p)) => Read (PatchOrReplacement p)
27+
28+
completePatchOrReplacement :: PatchOrReplacement p -> Maybe (PatchTarget p)
29+
completePatchOrReplacement = \case
30+
PatchOrReplacement_Complete t -> Just t
31+
PatchOrReplacement_Patch _ -> Nothing
32+
33+
instance ( Monoid p
34+
#if !MIN_VERSION_base(4,11,0)
35+
, Semigroup p
36+
#endif
37+
, Patch p
38+
) => Monoid (PatchOrReplacement p) where
39+
mempty = PatchOrReplacement_Patch mempty
40+
mappend = (<>)
41+
42+
instance (Semigroup p, Patch p) => Semigroup (PatchOrReplacement p) where
43+
(<>) = curry $ \case
44+
(PatchOrReplacement_Patch a, PatchOrReplacement_Patch b) -> PatchOrReplacement_Patch $ a <> b
45+
(PatchOrReplacement_Patch a, PatchOrReplacement_Complete b) -> PatchOrReplacement_Complete $ applyAlways a b
46+
(PatchOrReplacement_Complete a, _) -> PatchOrReplacement_Complete a

src/Data/Patch/Patchable.hs

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)