I Know What I Need, But I Don't Know How To Build It
Pick the thing you need. Then derive it: meaning, state, operations, rules, examples, representation, pseudocode — and only then the code, one rung at a time.
“I know I need a shopping cart. I have no idea how to implement a shopping cart.” The gap is not a missing tutorial; it is a missing method. Every stage below asks you to write before it shows you anything, because the code is the last step of a derivation, not the first thing to search for.
Which concept?
Grouped by exercise level; the level is how far the derivation goes, not how hard the code is.
How much help?
Every stage's content is shown right after your attempt box.
Pagination — twelve stages
I know I need pagination. I have no idea how to implement it so that nothing is skipped or shown twice.
Define the concept
In one sentence, without any code: what is it? Then answer for yourself — does it have identity, who owns it, how long does it exist, should it survive a reload or a login?
Pagination = A way of handing a long ordered list to a reader in bounded pieces, such that walking every piece visits each item once.
- Does a page have identity? No. A page is a view, not a thing: page 3 today and page 3 after an insert are different sets of items with the same label. What has identity is the position in the list — and that is the difference between an offset and a cursor.
- Who owns it? The reader. Two readers on the same list hold different positions; the list itself belongs to whoever owns the items and knows nothing about pages.
- How long does it exist? One page request — unless the reader is walking the whole list, in which case the position must survive between requests, which is exactly what a page token is for.
- Should it survive reload? The position should be shareable as a URL — ?page=3 or ?after=token — so that a reload lands where the reader was. Whether the items under that position are still the same is the concurrency question, not the identity question.
- Does it depend on the order of the list? Entirely. Pagination without a total order is undefined: two requests for the same page can return different items even with no writes. The sort key is part of the concept, not a detail.
The catalog is one derivation, not the only one (impl §60). A different set of examples yields different rules; a different first requirement yields a different V1; a map instead of an array is not wrong, only an answer to a different question. Compare your derivation with the reference for the differences, then decide which ones were rules and which were style.
Take it further
The flagship exercise: the cart typed by you, with the reference hidden until you ask.
Make It Smaller Until You Know How to Build It →The principle behind the ladder, and the primitive chain it produces.
The Implementation Loop →The loop the twelve stages follow, and why the code is last.