From 1134f0de9b681bc5d72ef73b36f7226bf47027dd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 12 Sep 2024 15:52:15 -0400 Subject: [PATCH] Two small fixes 1. Restore a `Data.Semigroup.Commutative` reexport accidentally removed in #56. (I accidentally forgot to notice during review.) 2. Replace partial `Map.lookup` with proper custom error for internal error. (This would make debugging a bug in the implementation easier.) This was part of #55. Co-Authoredy-By: Dmitry Olshansky --- src/Data/Patch.hs | 1 + src/Data/Patch/MapWithPatchingMove.hs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Data/Patch.hs b/src/Data/Patch.hs index 0f5cef6..b8c805b 100644 --- a/src/Data/Patch.hs +++ b/src/Data/Patch.hs @@ -28,6 +28,7 @@ import Control.Applicative (liftA2) import Data.Semigroup (Semigroup (..)) #endif +import qualified Data.Semigroup.Commutative as X import Data.Patch.Class as X import Data.Patch.DMap as X hiding (getDeletions) import Data.Patch.DMapWithMove as X diff --git a/src/Data/Patch/MapWithPatchingMove.hs b/src/Data/Patch/MapWithPatchingMove.hs index 62d1db2..82aaf26 100644 --- a/src/Data/Patch/MapWithPatchingMove.hs +++ b/src/Data/Patch/MapWithPatchingMove.hs @@ -231,8 +231,9 @@ patchThatSortsMapWith cmp m = PatchMapWithPatchingMove $ Map.fromList $ catMaybe Just (from, to) reverseMapping = Map.fromList $ catMaybes $ zipWith f unsorted sorted g (to, _) (from, _) = if to == from then Nothing else - let Just movingTo = Map.lookup from reverseMapping + let movingTo = fromMaybe err $ Map.lookup from reverseMapping in Just (to, NodeInfo (From_Move from mempty) $ Just movingTo) + err = error "IMPOSSIBLE happens in patchThatSortsMapWith" -- | Create a 'PatchMapWithPatchingMove' that, if applied to the first 'Map' provided, -- will produce a 'Map' with the same values as the second 'Map' but with the