* Attach a transform function to math.filter * Adds a property transform containing the transform function. * * This transform adds support for equations as test function for math.filter, * so you can do something like 'filter([3, -2, 5], x > 0)'.
(args, math, scope)
| 16 | * so you can do something like 'filter([3, -2, 5], x > 0)'. |
| 17 | */ |
| 18 | function filterTransform (args, math, scope) { |
| 19 | const filter = createFilter({ typed }) |
| 20 | const transformCallback = createTransformCallback({ typed }) |
| 21 | |
| 22 | if (args.length === 0) { |
| 23 | return filter() |
| 24 | } |
| 25 | let x = args[0] |
| 26 | |
| 27 | if (args.length === 1) { |
| 28 | return filter(x) |
| 29 | } |
| 30 | |
| 31 | const N = args.length - 1 |
| 32 | let callback = args[N] |
| 33 | |
| 34 | if (x) { |
| 35 | x = _compileAndEvaluate(x, scope) |
| 36 | } |
| 37 | |
| 38 | if (callback) { |
| 39 | if (isSymbolNode(callback) || isFunctionAssignmentNode(callback)) { |
| 40 | // a function pointer, like filter([3, -2, 5], myTestFunction) |
| 41 | callback = _compileAndEvaluate(callback, scope) |
| 42 | } else { |
| 43 | // an expression like filter([3, -2, 5], x > 0) |
| 44 | callback = compileInlineExpression(callback, math, scope) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return filter(x, transformCallback(callback, N)) |
| 49 | } |
| 50 | filterTransform.rawArgs = true |
| 51 | |
| 52 | function _compileAndEvaluate (arg, scope) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…