1 | 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); }
|
---|
2 | 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; }
|
---|
3 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
4 | 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); }
|
---|
5 | import { equals, pathSatisfies } from 'ramda';
|
---|
6 | import isString from '../isString';
|
---|
7 | import isNumber from '../isNumber';
|
---|
8 | import isFunction from '../isFunction';
|
---|
9 | import { isSameType } from './util';
|
---|
10 | import * as fl from './mapping';
|
---|
11 | export var functorTrait = _defineProperty({}, fl.map, function (fn) {
|
---|
12 | return this.constructor[fl.of](fn(this.value));
|
---|
13 | });
|
---|
14 | export var applyTrait = _defineProperty({}, fl.ap, function (applyWithFn) {
|
---|
15 | var _this = this;
|
---|
16 | return applyWithFn.map(function (fn) {
|
---|
17 | return fn(_this.value);
|
---|
18 | });
|
---|
19 | });
|
---|
20 | export var setoidTrait = _defineProperty({}, fl.equals, function (setoid) {
|
---|
21 | return isSameType(this, setoid) && equals(this.value, setoid.value);
|
---|
22 | });
|
---|
23 | export var semigroupTrait = _defineProperty({}, fl.concat, function (semigroup) {
|
---|
24 | var concatenatedValue = this.value;
|
---|
25 | if (isString(this.value) || isNumber(this.value)) {
|
---|
26 | concatenatedValue = this.value + semigroup.value;
|
---|
27 | } else if (pathSatisfies(isFunction, ['value', fl.concat], this)) {
|
---|
28 | concatenatedValue = this.value[fl.concat](semigroup.value);
|
---|
29 | } else if (pathSatisfies(isFunction, ['value', 'concat'], this)) {
|
---|
30 | concatenatedValue = this.value.concat(semigroup.value);
|
---|
31 | }
|
---|
32 | return this.constructor[fl.of](concatenatedValue);
|
---|
33 | });
|
---|
34 | export var chainTrait = _defineProperty({}, fl.chain, function (fn) {
|
---|
35 | var newChain = fn(this.value);
|
---|
36 | return isSameType(this, newChain) ? newChain : this;
|
---|
37 | });
|
---|
38 | export var ordTrait = _defineProperty({}, fl.lte, function (ord) {
|
---|
39 | return isSameType(this, ord) && (this.value < ord.value || this[fl.equals](ord));
|
---|
40 | }); |
---|