Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint: Typing

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 120 of 169

Design a generic Repository protocol and its in-memory implementation.

Checkpoint โ€” a typed repository

Build:

  1. class Repository(Protocol[T]) with add(item: T) -> None, get(key: str) -> Optional[T], all() -> List[T] (protocol bodies use ...).
  2. class MemoryRepository(Generic[T]) implementing it, constructed with a key_fn used to derive each item's key.
  3. seed(repo, users) adding every user.

Contract detail: add keeps the FIRST item for a key (later duplicates are ignored โ€” get() and all() still return the first).