Write a polyfill for Promise
Asked in the phone screen stage. Implement a Promise-like abstraction that supports resolution, rejection, .then() chaining, and .catch() recovery. For JSON-testable input, represent callbacks with operation names.
promise_polyfill(steps) receives an ordered list beginning with {"op": "resolve", "value": v} or {"op": "reject", "reason": r}. Later steps may be then or catch, with handlers identity, double, or constant. Return {"state": "fulfilled", "value": v} or {"state": "rejected", "reason": r}.
def promise_polyfill(steps):