github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/operator.go (about)

     1  package isc
     2  
     3  func ListPlus[T any](list []T, n []T) []T {
     4  	var t []T
     5  	for _, e := range list {
     6  		t = append(t, e)
     7  	}
     8  	for _, e := range n {
     9  		if !ListContains(t, e) {
    10  			t = append(t, e)
    11  		}
    12  	}
    13  	return t
    14  }
    15  
    16  func ListMinus[T any](list []T, n []T) []T {
    17  	var t []T
    18  	for _, e := range list {
    19  		if !ListContains(n, e) {
    20  			t = append(t, e)
    21  		}
    22  	}
    23  	return t
    24  }
    25  
    26  func MapPlus[K comparable, V any](m map[K]V, n map[K]V) map[K]V {
    27  	r := make(map[K]V)
    28  	for k, v := range m {
    29  		r[k] = v
    30  	}
    31  	for k, v := range n {
    32  		r[k] = v
    33  	}
    34  	return r
    35  }
    36  
    37  func MapMinus[K comparable, V any](m map[K]V, n map[K]V) map[K]V {
    38  	r := make(map[K]V)
    39  	for k, v := range m {
    40  		if _, ok := n[k]; !ok {
    41  			r[k] = v
    42  		}
    43  	}
    44  	return r
    45  }