Problem, as an interviewer would state it:
"Implement a minimal Observable class with .subscribe(), plus .map() and .filter() operators — like a simplified RxJS. Operators should be genuinely LAZY, only running once something actually subscribes."
Examples:
const doubled = source.map(n => n * 2).filter(n => n > 10);
doubled.subscribe({ next: v => console.log(v) }); // NOTHING ran until this line
Clarifying questions expected:
- Must map()/filter() be genuinely lazy, doing nothing at all until subscribe() is called?
- Does each operator need to correctly forward error and complete notifications, not just next values?
- Should subscribe() return an unsubscribe function, matching real Observable conventions?
Code / implementation expected: Yes — real, direct proof of genuine laziness: a real counter confirming zero operator calls happen before subscribe(), and exactly one call per real emission once subscribed.