A generic collection needs a constraint when its operations compare stored values. In Go, `comparable` restricts a type parameter to types that support `==` and `!=`. That lets equality-dependent operations be checked at compile time. section 6.1
An equality-aware linked list
Declare `LinkedList[T comparable]` when the list needs to find or remove an item by comparing it with stored values. Its constructor carries the same constraint: `func NewLinkedList[T comparable]() *LinkedList[T]`. Methods such as `Contains` and `Remove` can then test `curr.value == item`. section 6.1 section 6.2 section 6.3
Listing 6.14 Implementing part of the interface
func (l *LinkedList[T]) Remove(item T) bool { #1
var prev *node[T]
curr := l.head
for curr != nil {
if curr.value == item { #2
if prev == nil {
l.head = curr.next #3
} else {
prev.next = curr.next #4
}
l.size-- #5
return true
}
prev = curr
curr = curr.next
}
return false
}
func (l *LinkedList[T]) Contains(item T) bool { #6
curr := l.head
for curr != nil {
if curr.value == item { #7
return true
}
curr = curr.next
}
return false
}
func (l *LinkedList[T]) Size() int { #8
return l.size
}
func (l *LinkedList[T]) Clear() { #9
l.head = nil
l.size = 0
}
The `Remove` and `Contains` methods show where the constraint pays off: both traverse the list and compare each stored value with the requested item. section 6.3
The broader `List[T any]` interface describes operations without requiring equality. A concrete `LinkedList[T comparable]` can implement that interface while accepting only element types suitable for its equality-based methods. Choose the constraint for the operations an implementation performs, rather than making every collection require comparison. section 6.1 section 6.3


