MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / match

Function match

test/compute-engine/patterns.test.ts:14–35  ·  view source on GitHub ↗
(
  pattern: ExpressionInput,
  expr: Expression | MathJsonExpression,
  options?: PatternMatchOptions
)

Source from the content-addressed store, hash-verified

12const ce = engine;
13
14function match(
15 pattern: ExpressionInput,
16 expr: Expression | MathJsonExpression,
17 options?: PatternMatchOptions
18): Substitution | null {
19 // Avoid re-boxing both expr & pattern so as to preserve canonical-status
20 expr =
21 expr instanceof _BoxedExpression ? (expr as Expression) : ce.expr(expr);
22 pattern =
23 pattern instanceof _BoxedExpression
24 ? (pattern as Expression)
25 : ce.expr(pattern);
26
27 const result = expr.match(pattern, {
28 useVariations: true,
29 ...options,
30 });
31 if (result === null) return null;
32 const r = {};
33 for (const key of Object.keys(result)) r[key] = result[key];
34 return r;
35}
36
37describe('Examples from Patterns and Rules guide', () => {
38 const pattern: MathJsonExpression = ['Add', '_', 'x'];

Callers 2

patterns.test.tsFile · 0.70
match2Function · 0.70

Calls 3

exprMethod · 0.65
matchMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected