@hiki9/rich-domain
Version:
Rich Domain is a library that provides a set of tools to help you build complex business logic in NodeJS using Domain Driven Design principles.
53 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.combine = exports.ok = exports.fail = exports.Ok = exports.Fail = void 0;
class Fail {
constructor(value) {
this._value = value;
}
getValue() {
return this._value;
}
isFail() {
return true;
}
isSuccess() {
return false;
}
}
exports.Fail = Fail;
class Ok {
constructor(value) {
this._value = value;
}
getValue() {
return this._value;
}
isFail() {
return false;
}
isSuccess() {
return true;
}
}
exports.Ok = Ok;
const fail = (l) => {
return new Fail(l);
};
exports.fail = fail;
const ok = (a) => {
return new Ok(a);
};
exports.ok = ok;
const combine = (results) => {
const values = [];
for (const result of results) {
if (result.isFail()) {
return (0, exports.fail)(result.getValue());
}
values.push(result.getValue());
}
return (0, exports.ok)(values);
};
exports.combine = combine;
//# sourceMappingURL=result.js.map