[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports.setoidTrait = exports.semigroupTrait = exports.ordTrait = exports.functorTrait = exports.chainTrait = exports.applyTrait = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _isString = _interopRequireDefault(require("../isString"));
|
---|
| 7 | var _isNumber = _interopRequireDefault(require("../isNumber"));
|
---|
| 8 | var _isFunction = _interopRequireDefault(require("../isFunction"));
|
---|
| 9 | var _util = require("./util");
|
---|
| 10 | var fl = _interopRequireWildcard(require("./mapping"));
|
---|
| 11 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
---|
| 12 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
---|
| 13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 14 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
---|
| 15 | function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
---|
| 16 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
| 17 | function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
---|
| 18 | var functorTrait = _defineProperty({}, fl.map, function (fn) {
|
---|
| 19 | return this.constructor[fl.of](fn(this.value));
|
---|
| 20 | });
|
---|
| 21 | exports.functorTrait = functorTrait;
|
---|
| 22 | var applyTrait = _defineProperty({}, fl.ap, function (applyWithFn) {
|
---|
| 23 | var _this = this;
|
---|
| 24 | return applyWithFn.map(function (fn) {
|
---|
| 25 | return fn(_this.value);
|
---|
| 26 | });
|
---|
| 27 | });
|
---|
| 28 | exports.applyTrait = applyTrait;
|
---|
| 29 | var setoidTrait = _defineProperty({}, fl.equals, function (setoid) {
|
---|
| 30 | return (0, _util.isSameType)(this, setoid) && (0, _ramda.equals)(this.value, setoid.value);
|
---|
| 31 | });
|
---|
| 32 | exports.setoidTrait = setoidTrait;
|
---|
| 33 | var semigroupTrait = _defineProperty({}, fl.concat, function (semigroup) {
|
---|
| 34 | var concatenatedValue = this.value;
|
---|
| 35 | if ((0, _isString["default"])(this.value) || (0, _isNumber["default"])(this.value)) {
|
---|
| 36 | concatenatedValue = this.value + semigroup.value;
|
---|
| 37 | } else if ((0, _ramda.pathSatisfies)(_isFunction["default"], ['value', fl.concat], this)) {
|
---|
| 38 | concatenatedValue = this.value[fl.concat](semigroup.value);
|
---|
| 39 | } else if ((0, _ramda.pathSatisfies)(_isFunction["default"], ['value', 'concat'], this)) {
|
---|
| 40 | concatenatedValue = this.value.concat(semigroup.value);
|
---|
| 41 | }
|
---|
| 42 | return this.constructor[fl.of](concatenatedValue);
|
---|
| 43 | });
|
---|
| 44 | exports.semigroupTrait = semigroupTrait;
|
---|
| 45 | var chainTrait = _defineProperty({}, fl.chain, function (fn) {
|
---|
| 46 | var newChain = fn(this.value);
|
---|
| 47 | return (0, _util.isSameType)(this, newChain) ? newChain : this;
|
---|
| 48 | });
|
---|
| 49 | exports.chainTrait = chainTrait;
|
---|
| 50 | var ordTrait = _defineProperty({}, fl.lte, function (ord) {
|
---|
| 51 | return (0, _util.isSameType)(this, ord) && (this.value < ord.value || this[fl.equals](ord));
|
---|
| 52 | });
|
---|
| 53 | exports.ordTrait = ordTrait; |
---|