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

Function mapArgs

src/math-json/utils.ts:393–409  ·  view source on GitHub ↗
(
  expr: MathJsonExpression,
  fn: (x: MathJsonExpression) => T
)

Source from the content-addressed store, hash-verified

391 * Apply a function to the arguments of a function and return an array of T
392 */
393export function mapArgs<T>(
394 expr: MathJsonExpression,
395 fn: (x: MathJsonExpression) => T
396): T[] {
397 let args: MathJsonExpression[] | null = null;
398 if (Array.isArray(expr)) args = expr;
399 if (isFunctionObject(expr)) args = expr.fn;
400 if (args === null) return [];
401 let i = 1;
402 const result: T[] = [];
403 while (i < args.length) {
404 result.push(fn(args[i]));
405 i += 1;
406 }
407
408 return result;
409}
410
411/**
412 * Assuming that op is an associative operator, fold lhs or rhs

Callers 6

serializeCortexFunction · 0.90
serializeGenericFunctionFunction · 0.90
serializeOperatorFunction · 0.90
parse-cortex.tsFile · 0.90
serializeLatexTokensFunction · 0.90

Calls 2

isFunctionObjectFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected