Innovenergy_trunk/frontend/node_modules/fp-ts/lib/Ring.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionRing = exports.getTupleRing = exports.negate = exports.tuple = void 0;
/**
* The `Ring` class is for types that support addition, multiplication, and subtraction operations.
*
* Instances must satisfy the following law in addition to the `Semiring` laws:
*
* - Additive inverse: `a - a <-> (zero - a) + a <-> zero`
*
* Adapted from https://github.com/purescript/purescript-prelude/blob/master/src/Data/Ring.purs
*
* @since 2.0.0
*/
var function_1 = require("./function");
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* Given a tuple of `Ring`s returns a `Ring` for the tuple
*
* @example
* import { tuple } from 'fp-ts/Ring'
* import * as N from 'fp-ts/number'
*
* const R = tuple(N.Field, N.Field, N.Field)
* assert.deepStrictEqual(R.add([1, 2, 3], [4, 5, 6]), [5, 7, 9])
* assert.deepStrictEqual(R.mul([1, 2, 3], [4, 5, 6]), [4, 10, 18])
* assert.deepStrictEqual(R.one, [1, 1, 1])
* assert.deepStrictEqual(R.sub([1, 2, 3], [4, 5, 6]), [-3, -3, -3])
* assert.deepStrictEqual(R.zero, [0, 0, 0])
*
* @since 2.10.0
*/
var tuple = function () {
var rings = [];
for (var _i = 0; _i < arguments.length; _i++) {
rings[_i] = arguments[_i];
}
return ({
add: function (x, y) { return rings.map(function (R, i) { return R.add(x[i], y[i]); }); },
zero: rings.map(function (R) { return R.zero; }),
mul: function (x, y) { return rings.map(function (R, i) { return R.mul(x[i], y[i]); }); },
one: rings.map(function (R) { return R.one; }),
sub: function (x, y) { return rings.map(function (R, i) { return R.sub(x[i], y[i]); }); }
});
};
exports.tuple = tuple;
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
/**
* `negate x` can be used as a shorthand for `zero - x`
*
* @since 2.0.0
*/
var negate = function (R) {
return function (a) {
return R.sub(R.zero, a);
};
};
exports.negate = negate;
// -------------------------------------------------------------------------------------
// deprecated
// -------------------------------------------------------------------------------------
/**
* Use [`tuple`](#tuple) instead.
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
exports.getTupleRing = exports.tuple;
/**
* Use [`getRing`](./function.ts.html#getring) instead.
*
* @category zone of death
* @since 2.0.0
* @deprecated
*/
exports.getFunctionRing = function_1.getRing;