You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
443 B
JavaScript

"use strict";
const { NoMatch, NotEnoughInput } = require("./symbols");
// This is a utility function for propagating NoMatches through the stack, without resorting to `throw`/`catch` (which can be slow)
// FIXME: Use a Result type instead?
module.exports = function ifMatch(testResult, produceResult) {
if (testResult === NoMatch || testResult === NotEnoughInput) {
return testResult;
} else {
return produceResult(testResult);
}
};