chrisdone-archive / ini

Quick and easy INI configuration files for Haskell
Other
23 stars 17 forks source link

Semigroup could combine sections #31

Open chris-martin opened 3 years ago

chris-martin commented 3 years ago

When semigroupally combining Ini values that both define the same section, I was surprised to find that one of the sections is discarded. The monoid instance currently looks like this:

mappend x y = Ini {iniGlobals = mempty, iniSections = iniSections x <> iniSections y}

I was expecting sections of the same name to be merged.

Also, why discard all the globals?

Proposed change to the monoid instance:

mappend x y = Ini {
    iniGlobals = Map.unionWith (<>) (iniGlobals x) (iniGlobals y),
    iniSections = Map.unionWith (<>) (iniSections x) (iniSections y) }

Either way, whether you are interested in changing the instance or not, I'd be happy to send a PR with some documentation to mention how the instance behaves.

chrisdone commented 3 years ago

Good catch, classic map appending bug. Please PR and I’ll merge!

👌🙂