From 7411f4bf161a2c441b98fe2de6b6f220c56ee58f Mon Sep 17 00:00:00 2001 From: Amitai Burstein Date: Fri, 20 Oct 2023 14:30:55 +0300 Subject: [PATCH] Implement `isEmpty` for `Data.Map` --- IHP/HaskellSupport.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/IHP/HaskellSupport.hs b/IHP/HaskellSupport.hs index 92f18cdfc..0bf56b06b 100644 --- a/IHP/HaskellSupport.hs +++ b/IHP/HaskellSupport.hs @@ -50,6 +50,7 @@ import qualified Data.Attoparsec.ByteString.Char8 as Attoparsec import Data.String.Conversions (cs, ConvertibleStrings (..)) import qualified Debug.Trace import qualified Data.Text as Text +import qualified Data.Map as Map import qualified Data.ByteString.Char8 as ByteString import qualified Data.Aeson.Key as Aeson @@ -86,6 +87,10 @@ instance IsEmpty UUID.UUID where isEmpty uuid = UUID.nil == uuid {-# INLINE isEmpty #-} +instance IsEmpty (Map a b) where + isEmpty = Map.null + {-# INLINE isEmpty #-} + ifOrEmpty :: (Monoid a) => Bool -> a -> a ifOrEmpty bool a = if bool then a else mempty {-# INLINE ifOrEmpty #-} @@ -445,4 +450,4 @@ allEnumValues = enumFrom (toEnum 0) instance ConvertibleStrings ByteString Aeson.Key where convertString byteString = Aeson.fromText (cs byteString) instance ConvertibleStrings Text Aeson.Key where - convertString text = Aeson.fromText text \ No newline at end of file + convertString text = Aeson.fromText text