From f508e185900637da22d6fbf4f139cabd428070f4 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Tue, 21 Jul 2020 03:07:46 +0200 Subject: [PATCH] alterF: Skip deleting the key when it's already absent (#288) Fixes #287. --- Data/HashMap/Internal.hs | 2 +- Data/HashMap/Internal/Strict.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Data/HashMap/Internal.hs b/Data/HashMap/Internal.hs index 656dc14c..a572ab5f 100644 --- a/Data/HashMap/Internal.hs +++ b/Data/HashMap/Internal.hs @@ -1282,7 +1282,7 @@ alterF f = \ !k !m -> mv = lookup' h k m in (<$> f mv) $ \fres -> case fres of - Nothing -> delete' h k m + Nothing -> maybe m (const (delete' h k m)) mv Just v' -> insert' h k v' m -- We unconditionally rewrite alterF in RULES, but we expose an diff --git a/Data/HashMap/Internal/Strict.hs b/Data/HashMap/Internal/Strict.hs index 971ebd7e..b774cf41 100644 --- a/Data/HashMap/Internal/Strict.hs +++ b/Data/HashMap/Internal/Strict.hs @@ -314,7 +314,7 @@ alterF f = \ !k !m -> mv = lookup' h k m in (<$> f mv) $ \fres -> case fres of - Nothing -> delete' h k m + Nothing -> maybe m (const (delete' h k m)) mv Just !v' -> insert' h k v' m -- We rewrite this function unconditionally in RULES, but we expose