Condition
The Condition class represents a boolean match and/or a transformation of the input
values.
import { Condition } from 'pattahn/core';
You can subclass Condition by defining a constructor (which passes the name to
super) and an exec method which takes at least one argument and returns null or an
array of results. Here's the simplest Condition: the identity condition.
class Id extends Condition {constructor() {super('Id');}exec(...args) {return args;}}module.exports = Id.factory;const result = Id.factory().exec(7);expect(result).toEqual([7]);// The class is also exposed as a property of the factoryexpect(Id.factory.class).toBe(Id);
There's a .factory getter on Condition that simply allows the class to be
constructed without new. All first-party conditions export the factory to clean up
the consuming code.