Skip to content

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)

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] }

Source

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

Source