Proposal Details

I recently completed the Tour of Go and noticed that the last page of the generics section suggests adding functionality to the list implementation as an exercise. Unlike previous sections, this one lacks a structured exercise. To address this, I propose adding a hands-on exercise that involves implementing a Find method for a generic singly linked list. This addition will make the learning experience more comprehensive and beneficial.

Proposed Exercise:

Name: Exercise: Find Item Description:

In this exercise, you will implement the Find method for a generic singly linked list in Go. 
The Find method should search through the list and return the first node that contains the specified data. 
If the data is not found, the method should return nil.

Starter Code:

package main

import (
    "fmt"
)

type Node[T comparable] struct {
    Data T
    Next *Node[T]
}

type LinkedList[T comparable] struct {
    Head *Node[T]
}

func (ll *LinkedList[T]) Add(values ...T) {
    for _, value := range values {
        newNode := &Node[T]{Data: value, Next: ll.Head}
        ll.Head = newNode
    }
}

func (ll *LinkedList[T]) Find(data T) *Node[T] {
    // TODO: Implement the Find method
}

func main() {
    ll := LinkedList[int]{}
    ll.Add(10, 20, 30)

    if node := ll.Find(20); node != nil {
        fmt.Println("Found:", node.Data)
    } else {
        fmt.Println("Value not found")
    }
}

I know how to proceed with a pull request for this proposed exercise. However, I believe it's important to discuss this in an issue first to gather feedback and ensure it aligns well with the educational goals and structure of the module. I look forward to the community's input.

Comment From: seankhliao

I believe this should be an issue opened on the https://github.com/golang/tour/issues repo itself

Comment From: seankhliao

Duplicate of golang/tour#1423