ini icon indicating copy to clipboard operation
ini copied to clipboard

Semigroup could combine sections

Open chris-martin opened this issue 4 years ago • 1 comments

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.

chris-martin avatar Aug 01 '21 21:08 chris-martin

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

👌🙂

chrisdone avatar Aug 01 '21 23:08 chrisdone