MCPcopy
hub / github.com/josdejong/mathjs / mapTransform

Function mapTransform

src/expression/transform/map.transform.js:20–47  ·  view source on GitHub ↗
(args, math, scope)

Source from the content-addressed store, hash-verified

18 const transformCallback = createTransformCallback({ typed })
19
20 function mapTransform (args, math, scope) {
21 if (args.length === 0) {
22 return map()
23 }
24
25 if (args.length === 1) {
26 return map(args[0])
27 }
28 const N = args.length - 1
29 let X = args.slice(0, N)
30 let callback = args[N]
31 X = X.map(arg => _compileAndEvaluate(arg, scope))
32
33 if (callback) {
34 if (isSymbolNode(callback) || isFunctionAssignmentNode(callback)) {
35 // a function pointer, like filter([3, -2, 5], myTestFunction)
36 callback = _compileAndEvaluate(callback, scope)
37 } else {
38 // an expression like filter([3, -2, 5], x > 0)
39 callback = compileInlineExpression(callback, math, scope)
40 }
41 }
42 return map(...X, transformCallback(callback, N))
43
44 function _compileAndEvaluate (arg, scope) {
45 return arg.compile().evaluate(scope)
46 }
47 }
48 mapTransform.rawArgs = true
49
50 return mapTransform

Callers

nothing calls this directly

Calls 6

isSymbolNodeFunction · 0.90
isFunctionAssignmentNodeFunction · 0.90
compileInlineExpressionFunction · 0.90
mapFunction · 0.85
_compileAndEvaluateFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…