contains

package
v0.0.0-...-886b66b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

The deriveContains function returns whether an element exists in a list.

Given the following input:

package contains

import (
	"fmt"
)

type boat struct {
	id int
}

func appendUnique(olds, news []boat) ([]boat, error) {
	for i := range news {
		if deriveContains(olds, news[i]) {
			return nil, fmt.Errorf("duplicate found")
		}
	}
	return append(olds, news...), nil
}

goderive will generate the following code:

// Code generated by goderive DO NOT EDIT.

package contains

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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL