import Data.List as L (union)
import Data.List.Split
import Data.Char
-import Data.Map as M (Map, lookup, delete, size, union)
+import Data.Map as M (Map, lookup, delete, size, unionWith)
import Data.Vector (toList,(!),length, singleton)
import Control.Applicative ((<$>), (<*>), empty, pure)
import Data.Aeson
class Mergeable a where
merge :: a -> a -> a -- bias towads second arg
-instance Ord k => Mergeable (Map k a) where
- merge mx my = M.union my mx
+instance (Ord k, Mergeable a) => Mergeable (Map k a) where
+ merge mx my = M.unionWith merge my mx
-- instance Mergeable String where
-- merge _ b = b
-{"service":[["smtp", "tcp", 0, 0, 25, "mail.host.com."]],"import":"d/extra2","ip":["1.2.3.4"],"alias":"extra1alias"}
+{"service":[["smtp", "tcp", 0, 0, 25, "mail.host.com."]],"import":"d/extra2","ip":["1.2.3.4"],"alias":"extra1alias","map":{"mail":"1.1.1.1","www":"1.1.1.1"}}
-{"ip":["5.6.7.8"],"alias":"extra2alias","service":[["imap", "tcp", 0, 0, 143, "mail.host.com."]]}
+{"ip":["5.6.7.8"],"alias":"extra2alias","service":[["imap", "tcp", 0, 0, 143, "mail.host.com."]],"map":{"ftp":"2.2.2.2","www":"2.2.2.2"}}