simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

sum.transform.js (1320B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createSumTransform = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _errorTransform = require("./utils/errorTransform.js");
     11 
     12 var _sum = require("../../function/statistics/sum.js");
     13 
     14 var _lastDimToZeroBase = require("./utils/lastDimToZeroBase.js");
     15 
     16 /**
     17  * Attach a transform function to math.sum
     18  * Adds a property transform containing the transform function.
     19  *
     20  * This transform changed the last `dim` parameter of function sum
     21  * from one-based to zero based
     22  */
     23 var name = 'sum';
     24 var dependencies = ['typed', 'config', 'add', 'numeric'];
     25 var createSumTransform = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     26   var typed = _ref.typed,
     27       config = _ref.config,
     28       add = _ref.add,
     29       numeric = _ref.numeric;
     30   var sum = (0, _sum.createSum)({
     31     typed: typed,
     32     config: config,
     33     add: add,
     34     numeric: numeric
     35   });
     36   return typed(name, {
     37     '...any': function any(args) {
     38       args = (0, _lastDimToZeroBase.lastDimToZeroBase)(args);
     39 
     40       try {
     41         return sum.apply(null, args);
     42       } catch (err) {
     43         throw (0, _errorTransform.errorTransform)(err);
     44       }
     45     }
     46   });
     47 }, {
     48   isTransformFunction: true
     49 });
     50 exports.createSumTransform = createSumTransform;