Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify mappend to avoid discarding #4

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 0.5.0

_2023-02-08, Chris Martin_

The behavior of `(<>)` for the `Ini` type has changed
[#2](https://github.com/andreasabel/ini/issues/2)

- `<>` 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.

Tested with GHC 7.0 - ghc-9.6.0.20230128.

## 0.4.2

_2022-07-26, Andreas Abel_
Expand Down
2 changes: 1 addition & 1 deletion ini.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Data/Ini.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down