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.

027 Interfaces and dynamic dispatch an interface as a method set, a value in an interface, dynamic dispatch and a slice of shapes Open 028 Implicit satisfaction and type switches implicit satisfaction, the empty interface, type assertions, type switches and the method a type lacks Open 029 Embedding instead of inheritance struct embedding, promoted fields and methods, an embedded interface and why this is not inheritance Open 030 Type parameters and constraints a type parameter, constraints, inferred type arguments and a generic function that works for many types Open 031 Generic types, inference and the standard library a generic type, constraint unions, inference rules and slices and maps in the standard library Open 032 Wrapping errors with %w fmt.Errorf with %w, Unwrap, a chain of context and the difference from %v Open 033 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 034 defer, order and named results defer, last in first out, arguments evaluated at the call, named results and a cleanup that always runs Open 035 panic, recover and the boundary panic, recover, a deferred recover, the boundary of a package and when a panic is the right answer Open 036 Recursion and the stack a base case, a recursive walk, the call stack, a memo and a depth limit Open 037 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 038 sort, slices.SortFunc and maps.Keys sort.Ints, slices.Sort, SortFunc with a comparison, sort.Stable and sorted map keys Open

Lessons