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.

15 lines
575 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?
// FIXME: Maybe we can get rid of this entirely? Now that we no longer have to handle NotEnoughInput within core-ops anymore at all
module.exports = function ifMatch(testResult, produceResult) {
if (testResult === NoMatch || testResult === NotEnoughInput) {
return testResult;
} else {
return produceResult(testResult);
}
};