/deepmerge

Merge 2 maps based on the function provided.

Primary LanguageGoMIT LicenseMIT

Inspired by deep_merge in rails.

Typical usage:

	map1 := map[string]int{
		"a": 10,
		"b": 3,
		"c": 12,
	}

	map2 := map[string]int{
		"a": 3,
		"b": 3,
		"c": 2,
	}

    add := func(a, b int) int { return a + b }
    d := &DeepMerge{
         map1: map1,
         map2: map2,
    }
    mergedMap, err := d.Merge(&add)

Expected Output(mergedMap):

	 map[string]int{
		"a": 13,
		"b": 6,
		"c": 14,
	}

There are more examples in deepmerge_test.go

Installation

go get -u github.com/sridharavinash/deepmerge

Tests

go test ./...