Codync
A free, open-source 1:1 alternative to Grok Bot and Muse. Message Claude Code, Codex, Cursor and 40+ coding agents as persistent bots from your iPhone, Mac or Linux desktop. Group chats, threads, appr
Vending machine LLD as one pure function: step(machine, event) → [machine, effects]
Translation pending
Developer toolsTypeScriptGitHub @abo3ishOnlineOwner unconfirmed
Have you tried it? One tap is enough. No sign-in needed.
No updates detected yet. GitHub releases will appear here.
Owners of public repositories under a personal GitHub account can sign in to verify ownership and manage the introduction themselves. No administrator approval is needed.
Sign in, generate a verification file, and commit it to this repository’s default branch within 30 minutes. Files on other branches or forks do not count. Then check the file below to manage the project without administrator approval. Keep the file to retain your access.
If needed, you will go to sign-in. After signing in, return here and press your chosen verification button again.
Run /nomorevibe verify in your project folder to verify ownership and manage the introduction yourself.
Verify in one minuteAsk about other verification options
The maker's introduction consists of the line above. Read the repository README for more details. Repository README ↗
Loading the full README.
Read the full README ↗The classic low-level design interview question, solved without the State pattern: the whole machine is one pure function.
step(machine, event) → [machine, effects]
▶ Try it in the animated walkthrough: buy something, jam the motor, run out of change, then scrub back through time and branch from any moment.
stateDiagram-v2
[*] --> idle
idle --> paying: select (in stock)
paying --> paying: insert / buy before fully paid
paying --> dispensing: buy (paid ≥ price, change possible)
paying --> idle: cancel / no change possible
dispensing --> idle: dispensed (commit) / jammed (refund)
| File | Role |
|---|---|
src/machine.ts | Types and step(): every (phase, event) pair, nothing else. No I/O, no clock, no mutation |
src/coins.ts | Integer cents, coin counts, makeChange() |
tests/properties.test.ts | fast-check: thousands of random event sequences against invariants |
docs/index.html | The shell: renders the machine and replays events through the same core (docs/vending.js is built from src/) |
The textbook solution is a VendingMachine class holding selectedProduct, totalCoins and currentState, plus a State pattern with Idle, Ready, Dispense and ReturnChange classes that call machine.setState(new ...).
switch is fine when the compiler checks it. The OOP answer rejects switch on Open/Closed grounds. With discriminated unions and noImplicitReturns, dropping a case fails the build, which is stronger than OCP for a closed set of states.idle has none and paying has slot and inserted. "Idle with a product selected" cannot be written down.{ tag: 'returnCoins', coins } and not a ReturnChangeState. Tests read effects like any value, and the page animates them.dispensed. On jammed the exact inserted coins go back and nothing was ever written.totalCoins = 135 cannot tell you whether 35¢ of change is possible. The box keeps counts per denomination, and that is the only way "Exact change only" fits in the design.makeChange backtracks and is checked against brute force.step one at a time. If the machine sits behind an API, serialising events per machine is the shell's job, and the core does not change.run(start, events) on every render.Hand-written scenarios cover the obvious paths. The property tests generate random machines and up to 60 random events (coins while dispensing, sensor signals out of nowhere, slots that do not exist) and check, at every step:
box + inserted = box' + returned + escrowmakeChange finds change exactly when brute force says it existsTo check they are not decorative: drop the line that pays change out of the box and three tests fail. Drop any case and tsc refuses to compile.
Requires Node 23+.
npm install
npm test # unit + property tests
npm run typecheck
npm run build:web # rebuild docs/vending.js after changing src/
Open docs/index.html through any static server, for example npx serve docs.