source: node_modules/ramda-adjunct/es/fantasy-land/traits.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1function _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); }
2function _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; }
3function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4function _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); }
5import { equals, pathSatisfies } from 'ramda';
6import isString from '../isString';
7import isNumber from '../isNumber';
8import isFunction from '../isFunction';
9import { isSameType } from './util';
10import * as fl from './mapping';
11export var functorTrait = _defineProperty({}, fl.map, function (fn) {
12 return this.constructor[fl.of](fn(this.value));
13});
14export var applyTrait = _defineProperty({}, fl.ap, function (applyWithFn) {
15 var _this = this;
16 return applyWithFn.map(function (fn) {
17 return fn(_this.value);
18 });
19});
20export var setoidTrait = _defineProperty({}, fl.equals, function (setoid) {
21 return isSameType(this, setoid) && equals(this.value, setoid.value);
22});
23export 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});
34export var chainTrait = _defineProperty({}, fl.chain, function (fn) {
35 var newChain = fn(this.value);
36 return isSameType(this, newChain) ? newChain : this;
37});
38export var ordTrait = _defineProperty({}, fl.lte, function (ord) {
39 return isSameType(this, ord) && (this.value < ord.value || this[fl.equals](ord));
40});
Note: See TracBrowser for help on using the repository browser.