Interfaces, generics and errors

A method set is a type, and a type satisfies it without saying so. These lessons go from the interface and dynamic dispatch through embedding, type parameters and constraints, then down the error chain: %w, errors.Is, errors.As, defer and the one recover that stops a panic. Recursion, closures and sorting close the part.

3.1 Interfaces and dynamic dispatch an interface as a method set, a value in an interface, dynamic dispatch and a slice of shapes Open 3.2 Implicit satisfaction and type switches implicit satisfaction, the empty interface, type assertions, type switches and the method a type lacks Open 3.3 Embedding instead of inheritance struct embedding, promoted fields and methods, an embedded interface and why this is not inheritance Open 3.4 Type parameters and constraints a type parameter, constraints, inferred type arguments and a generic function that works for many types Open 3.5 Generic types, inference and the standard library a generic type, constraint unions, inference rules and slices and maps in the standard library Open 3.6 Wrapping errors with %w fmt.Errorf with %w, Unwrap, a chain of context and the difference from %v Open 3.7 errors.Is, errors.As and sentinel errors sentinel errors, errors.Is, errors.As, a custom error type and the one place a caller unwraps Open 3.8 defer, order and named results defer, last in first out, arguments evaluated at the call, named results and a cleanup that always runs Open 3.9 panic, recover and the boundary panic, recover, a deferred recover, the boundary of a package and when a panic is the right answer Open 3.10 Recursion and the stack a base case, a recursive walk, the call stack, a memo and a depth limit Open 3.11 Closures, capture and range-over-func a closure that captures, the loop variable per iteration, a counter and an iterator with range-over-func Open 3.12 sort, slices.SortFunc and maps.Keys sort.Ints, slices.Sort, SortFunc with a comparison, sort.Stable and sorted map keys Open

Lessons