Applied
Advanced · Testing & Applied
Exercises that combine several concepts into something close to real code.
- applied1 — implement
sort.Interface(Len/Less/Swap) to sort a custom type - applied2 — a concurrency-safe key/value store (map + mutex + methods + sentinel error)
Resources
Section titled “Resources”Exercises
Section titled “Exercises”applied1 test
Section titled “applied1 test”applied1 — sort.Interface
Show hint
Implement the remaining sort.Interface methods:
func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age }func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }applied2 test
Section titled “applied2 test”applied2 — a concurrency-safe store
Show hint
Guard the write like the read does:
s.mu.Lock()defer s.mu.Unlock()s.m[key] = v