From 1046c497e7f9c52f2c2fe64761764648d1f00082 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Tue, 7 Feb 2023 14:15:37 -0700 Subject: [PATCH] Modify mappend to avoid discarding Closes #2 --- CHANGELOG.md | 12 ++++++++++++ ini.cabal | 2 +- src/Data/Ini.hs | 7 ++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b4aa4..40e4b13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## 0.5.0 + +The behavior of `(<>)` for the `Ini` type has changed. + +- `<>` previously discarded all `iniGlobals`. Now it concatenates + the globals from the two `Ini` values. + +- When two `Ini` values contained `iniSections` with the same name, + `<>` previously returned the section from the left value and + discarded the section of the same name from the right value. + Now it concatenates the sections of the same name. + ## 0.4.2 _2022-07-26, Andreas Abel_ diff --git a/ini.cabal b/ini.cabal index 1ec9bcb..3193daf 100644 --- a/ini.cabal +++ b/ini.cabal @@ -1,6 +1,6 @@ cabal-version: >= 1.10 name: ini -version: 0.4.2 +version: 0.5.0 synopsis: Configuration files in the INI format. description: Quick and easy configuration files in the INI format. license: BSD3 diff --git a/src/Data/Ini.hs b/src/Data/Ini.hs index f3201c7..ef3f237 100644 --- a/src/Data/Ini.hs +++ b/src/Data/Ini.hs @@ -89,8 +89,13 @@ data Ini = } deriving (Show, Eq) +-- | '<>' concatenates the lists of entries within each section (since @ini-0.5.0@) instance Semigroup Ini where - x <> y = Ini {iniGlobals = mempty, iniSections = iniSections x <> iniSections y} + x <> y = + Ini + { iniGlobals = iniGlobals x ++ iniGlobals y + , iniSections = M.unionWith (++) (iniSections x) (iniSections y) + } instance Monoid Ini where mempty = Ini {iniGlobals = mempty, iniSections = mempty}