package
0.5.1
Repository: https://github.com/awalterschulze/goderive.git
Documentation: pkg.go.dev

# README

The deriveIntersect function returns the intersect of two lists or maps.

Given the following input:

package intersect

func bestChoices(strategy1, strategy2 []int) []int {
	intersection := deriveIntersect(strategy1, strategy2)
	if len(intersection) == 0 {
		return append(strategy1, strategy2...)
	}
	return intersection
}

goderive will generate the following code:

// Code generated by goderive DO NOT EDIT.

package intersect

// deriveIntersect returns the intersection of the two lists' values
// It assumes that the first list only contains unique items.
//
// Deprecated: In favour of generics.
func deriveIntersect(this, that []int) []int {
	intersect := make([]int, 0, deriveMin(len(this), len(that)))
	for i, v := range this {
		if deriveContains(that, v) {
			intersect = append(intersect, this[i])
		}
	}
	return intersect
}

// deriveContains returns whether the item is contained in the list.
//
// Deprecated: In favour of generics.
func deriveContains(list []int, item int) bool {
	for _, v := range list {
		if v == item {
			return true
		}
	}
	return false
}

// deriveMin returns the minimum of the two input values.
//
// Deprecated: In favour of generics.
func deriveMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}