๐ 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:
class Repository(Protocol[T])withadd(item: T) -> None,get(key: str) -> Optional[T],all() -> List[T](protocol bodies use...).class MemoryRepository(Generic[T])implementing it, constructed with akey_fnused to derive each item's key.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).