JSFiddle - React, Tailwind, and code Playground
by jrab227
JavaScript
function ErrorWrapper(value, failing) {
this.condition = !failing;
this.value = value;
this.then = (f) => this.condition ? f(this.value) : this;
}
function foo(v) {
if (v === 'foo') return new ErrorWrapper('brokenaf', true);
return new ErrorWrapper('bar2');
}
function bar(v) {
return new ErrorWrapper(v + 'hello');
}
let k = new ErrorWrapper('foo');
let b = new ErrorWrapper('bar');
let res = k.then(foo).then(bar);
let res2 = b.then(foo).then(bar)
debugger