Skip to content

Commit

Permalink
Modify Semigroup behavior to avoid discarding (closes chrisdone-archi…
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Aug 2, 2021
1 parent c4cfe3a commit b18c194
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Changes to the `ini` package
=====

v0.5
-----

The behavior of `(<>)` and `mappend` 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.
3 changes: 2 additions & 1 deletion ini.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ini
version: 0.4.2
version: 0.5
synopsis: Quick and easy configuration files in the INI format.
description: Quick and easy configuration files in the INI format.
license: BSD3
Expand All @@ -12,6 +12,7 @@ copyright: 2013 Chris Done
category: Data, Configuration
build-type: Simple
cabal-version: >=1.8
extra-source-files: CHANGELOG.md

library
hs-source-dirs: src/
Expand Down
5 changes: 4 additions & 1 deletion src/Data/Ini.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ data Ini =
}
deriving (Show, Eq)

-- | '<>' concatenates the lists of entries within each section (since @ini-0.5@)
instance Semigroup Ini where
(<>) = mappend

instance Monoid Ini where
mempty = Ini {iniGlobals = mempty, iniSections = mempty}
mappend x y =
Ini {iniGlobals = mempty, iniSections = iniSections x <> iniSections y}
Ini { iniGlobals = iniGlobals x ++ iniGlobals y
, iniSections = M.unionWith (++) (iniSections x) (iniSections y)
}

{-# DEPRECATED #-}
unIni :: Ini -> HashMap Text (HashMap Text Text)
Expand Down

0 comments on commit b18c194

Please sign in to comment.