reactive-actor
Version:
Actor model implementation with rxjs
17 lines • 697 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.validate = void 0;
const rxjs_1 = require("rxjs");
/**
* Validates the source emitted value, throws an error when validation
* doesn't pass
* @param params -
* - validation: predicate function to test emitted value
* - error: message in case of error
* @returns an operator function that validates emitted values
*/
function validate({ validation, error = '', }) {
return (source$) => source$.pipe((0, rxjs_1.concatMap)((value) => validation(value) ? (0, rxjs_1.of)(value) : (0, rxjs_1.throwError)(() => new Error(error))));
}
exports.validate = validate;
//# sourceMappingURL=validate.operator.js.map
;