[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var fl = _interopRequireWildcard(require("./mapping"));
|
---|
| 7 | var _traits = require("./traits");
|
---|
| 8 | 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); }
|
---|
| 9 | 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; }
|
---|
| 10 | 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); }
|
---|
| 11 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
| 12 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
---|
| 13 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
---|
| 14 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
| 15 | 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); }
|
---|
| 16 | /**
|
---|
| 17 | * The simplest {@link https://github.com/fantasyland/fantasy-land|fantasy-land}
|
---|
| 18 | * compatible monad which attaches no information to values.
|
---|
| 19 | *
|
---|
| 20 | * The Identity type is a very simple type that has no interesting side effects and
|
---|
| 21 | * is effectively just a container of some value. So why does it exist ?
|
---|
| 22 | * The Identity type is often used as the base monad of a monad
|
---|
| 23 | * transformer when no other behaviour is required.
|
---|
| 24 | *
|
---|
| 25 | * @memberOf RA
|
---|
| 26 | * @implements
|
---|
| 27 | * {@link https://github.com/fantasyland/fantasy-land#apply|Apply},
|
---|
| 28 | * {@link https://github.com/fantasyland/fantasy-land#applicative|Applicative},
|
---|
| 29 | * {@link https://github.com/fantasyland/fantasy-land#functor|Functor},
|
---|
| 30 | * {@link https://github.com/fantasyland/fantasy-land#setoid|Setoid},
|
---|
| 31 | * {@link https://github.com/fantasyland/fantasy-land#semigroup|Semigroup},
|
---|
| 32 | * {@link https://github.com/fantasyland/fantasy-land#chain|Chain},
|
---|
| 33 | * {@link https://github.com/fantasyland/fantasy-land#monad|Monad},
|
---|
| 34 | * {@link https://github.com/fantasyland/fantasy-land#ord|Ord},
|
---|
| 35 | * {@link https://github.com/fantasyland/fantasy-land#monoid|Monoid*},
|
---|
| 36 | * {@link https://github.com/fantasyland/fantasy-land#contravariant|Contravariant}
|
---|
| 37 | * @since {@link https://char0n.github.io/ramda-adjunct/1.8.0|v1.8.0}
|
---|
| 38 | */
|
---|
| 39 | var Identity = /*#__PURE__*/function (_fl$of, _fl$ap, _fl$map, _fl$equals, _fl$concat, _fl$chain, _fl$lte, _fl$empty, _fl$contramap) {
|
---|
| 40 | /**
|
---|
| 41 | * Private constructor. Use {@link RA.Identity.of|Identity.of} instead.
|
---|
| 42 | *
|
---|
| 43 | * @param {*} value
|
---|
| 44 | * @return {RA.Identity}
|
---|
| 45 | */
|
---|
| 46 | function Identity(value) {
|
---|
| 47 | _classCallCheck(this, Identity);
|
---|
| 48 | this.value = value;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * Catamorphism for a value.
|
---|
| 53 | * @returns {*}
|
---|
| 54 | * @example
|
---|
| 55 | *
|
---|
| 56 | * const a = Identity.of(1);
|
---|
| 57 | * a.get(); //=> 1
|
---|
| 58 | */
|
---|
| 59 | _createClass(Identity, [{
|
---|
| 60 | key: "get",
|
---|
| 61 | value: function get() {
|
---|
| 62 | return this.value;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#apply|Apply} specification.
|
---|
| 67 | *
|
---|
| 68 | * @sig ap :: Apply f => f a ~> f (a -> b) -> f b
|
---|
| 69 | * @param {RA.Identity} applyWithFn
|
---|
| 70 | * @return {RA.Identity}
|
---|
| 71 | * @example
|
---|
| 72 | *
|
---|
| 73 | * const a = Identity.of(1);
|
---|
| 74 | * const b = Identity.of(1).map(a => b => a + b);
|
---|
| 75 | *
|
---|
| 76 | * a.ap(b); //=> Identity(2)
|
---|
| 77 | */
|
---|
| 78 | }, {
|
---|
| 79 | key: _fl$ap,
|
---|
| 80 | value: function value(applyWithFn) {
|
---|
| 81 | return _traits.applyTrait[fl.ap].call(this, applyWithFn);
|
---|
| 82 | }
|
---|
| 83 | }, {
|
---|
| 84 | key: "ap",
|
---|
| 85 | value: function ap(applyWithFn) {
|
---|
| 86 | return this[fl.ap](applyWithFn);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#functor|Functor} specification.
|
---|
| 91 | *
|
---|
| 92 | * @sig map :: Functor f => f a ~> (a -> b) -> f b
|
---|
| 93 | * @param {Function} fn
|
---|
| 94 | * @return {RA.Identity}
|
---|
| 95 | * @example
|
---|
| 96 | *
|
---|
| 97 | * const a = Identity.of(1);
|
---|
| 98 | * a.map(a => a + 1); //=> Identity(2)
|
---|
| 99 | */
|
---|
| 100 | }, {
|
---|
| 101 | key: _fl$map,
|
---|
| 102 | value: function value(fn) {
|
---|
| 103 | return _traits.functorTrait[fl.map].call(this, fn);
|
---|
| 104 | }
|
---|
| 105 | }, {
|
---|
| 106 | key: "map",
|
---|
| 107 | value: function map(fn) {
|
---|
| 108 | return this[fl.map](fn);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /**
|
---|
| 112 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#setoid|Setoid} specification.
|
---|
| 113 | *
|
---|
| 114 | * @sig equals :: Setoid a => a ~> a -> Boolean
|
---|
| 115 | * @param {RA.Identity} setoid
|
---|
| 116 | * @return {boolean}
|
---|
| 117 | * @example
|
---|
| 118 | *
|
---|
| 119 | * const a = Identity.of(1);
|
---|
| 120 | * const b = Identity.of(1);
|
---|
| 121 | * const c = Identity.of(2);
|
---|
| 122 | *
|
---|
| 123 | * a.equals(b); //=> true
|
---|
| 124 | * a.equals(c); //=> false
|
---|
| 125 | */
|
---|
| 126 | }, {
|
---|
| 127 | key: _fl$equals,
|
---|
| 128 | value: function value(setoid) {
|
---|
| 129 | return _traits.setoidTrait[fl.equals].call(this, setoid);
|
---|
| 130 | }
|
---|
| 131 | }, {
|
---|
| 132 | key: "equals",
|
---|
| 133 | value: function equals(setoid) {
|
---|
| 134 | return this[fl.equals](setoid);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#semigroup|Semigroup} specification.
|
---|
| 139 | *
|
---|
| 140 | * @sig concat :: Semigroup a => a ~> a -> a
|
---|
| 141 | * @param {RA.Identity} semigroup
|
---|
| 142 | * @return {RA.Identity}
|
---|
| 143 | * @example
|
---|
| 144 | *
|
---|
| 145 | * const a = Identity.of(1);
|
---|
| 146 | * const b = Identity.of(1);
|
---|
| 147 | * a.concat(b); //=> 2
|
---|
| 148 | *
|
---|
| 149 | * const c = Identity.of('c');
|
---|
| 150 | * const d = Identity.of('d');
|
---|
| 151 | * c.concat(d); //=> 'cd'
|
---|
| 152 | *
|
---|
| 153 | * const e = Identity.of(['e']);
|
---|
| 154 | * const f = Identity.of(['f']);
|
---|
| 155 | * e.concat(f); //=> ['e', 'f']
|
---|
| 156 | */
|
---|
| 157 | }, {
|
---|
| 158 | key: _fl$concat,
|
---|
| 159 | value: function value(semigroup) {
|
---|
| 160 | return _traits.semigroupTrait[fl.concat].call(this, semigroup);
|
---|
| 161 | }
|
---|
| 162 | }, {
|
---|
| 163 | key: "concat",
|
---|
| 164 | value: function concat(semigroup) {
|
---|
| 165 | return this[fl.concat](semigroup);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /**
|
---|
| 169 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#chain|Chain} specification.
|
---|
| 170 | *
|
---|
| 171 | * @sig chain :: Chain m => m a ~> (a -> m b) -> m b
|
---|
| 172 | * @param {Function} fn Function returning the value of the same {@link https://github.com/fantasyland/fantasy-land#semigroup|Chain}
|
---|
| 173 | * @return {RA.Identity}
|
---|
| 174 | * @example
|
---|
| 175 | *
|
---|
| 176 | * const a = Identity.of(1);
|
---|
| 177 | * const fn = val => Identity.of(val + 1);
|
---|
| 178 | *
|
---|
| 179 | * a.chain(fn).chain(fn); //=> Identity(3)
|
---|
| 180 | */
|
---|
| 181 | }, {
|
---|
| 182 | key: _fl$chain,
|
---|
| 183 | value: function value(fn) {
|
---|
| 184 | return _traits.chainTrait[fl.chain].call(this, fn);
|
---|
| 185 | }
|
---|
| 186 | }, {
|
---|
| 187 | key: "chain",
|
---|
| 188 | value: function chain(fn) {
|
---|
| 189 | return this[fl.chain](fn);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /**
|
---|
| 193 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#ord|Ord} specification.
|
---|
| 194 | *
|
---|
| 195 | * @sig lte :: Ord a => a ~> a -> Boolean
|
---|
| 196 | * @param {RA.Identity} ord
|
---|
| 197 | * @return {boolean}
|
---|
| 198 | * @example
|
---|
| 199 | *
|
---|
| 200 | * const a = Identity.of(1);
|
---|
| 201 | * const b = Identity.of(1);
|
---|
| 202 | * const c = Identity.of(2);
|
---|
| 203 | *
|
---|
| 204 | * a.lte(b); //=> true
|
---|
| 205 | * a.lte(c); //=> true
|
---|
| 206 | * c.lte(a); //=> false
|
---|
| 207 | */
|
---|
| 208 | }, {
|
---|
| 209 | key: _fl$lte,
|
---|
| 210 | value: function value(ord) {
|
---|
| 211 | return _traits.ordTrait[fl.lte].call(this, ord);
|
---|
| 212 | }
|
---|
| 213 | }, {
|
---|
| 214 | key: "lte",
|
---|
| 215 | value: function lte(ord) {
|
---|
| 216 | return this[fl.lte](ord);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | /**
|
---|
| 220 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#monoid|Monoid*} specification.
|
---|
| 221 | * Partial implementation of Monoid specification. `empty` method on instance only, returning
|
---|
| 222 | * identity value of the wrapped type. Using `R.empty` under the hood.
|
---|
| 223 | *
|
---|
| 224 | *
|
---|
| 225 | * @sig empty :: Monoid m => () -> m
|
---|
| 226 | * @return {RA.Identity}
|
---|
| 227 | * @example
|
---|
| 228 | *
|
---|
| 229 | * const a = Identity.of('test');
|
---|
| 230 | * const i = a.empty();
|
---|
| 231 | *
|
---|
| 232 | * a.concat(i); //=> Identity('string');
|
---|
| 233 | * i.concat(a); //=> Identity('string');
|
---|
| 234 | */
|
---|
| 235 | }, {
|
---|
| 236 | key: _fl$empty,
|
---|
| 237 | value: function value() {
|
---|
| 238 | return this.constructor.of((0, _ramda.empty)(this.value));
|
---|
| 239 | }
|
---|
| 240 | }, {
|
---|
| 241 | key: "empty",
|
---|
| 242 | value: function empty() {
|
---|
| 243 | return this[fl.empty]();
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
| 247 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#contravariant|Contravariant} specification.
|
---|
| 248 | *
|
---|
| 249 | * @sig contramap :: Contravariant f => f a ~> (b -> a) -> f b
|
---|
| 250 | * @param {Function} fn
|
---|
| 251 | * @return {RA.Identity}
|
---|
| 252 | * @example
|
---|
| 253 | *
|
---|
| 254 | * const identity = a => a;
|
---|
| 255 | * const add1 = a => a + 1;
|
---|
| 256 | * const divide2 = a => a / 2;
|
---|
| 257 | *
|
---|
| 258 | * Identity.of(divide2).contramap(add1).get()(3); //=> 2
|
---|
| 259 | * Identity.of(identity).contramap(divide2).contramap(add1).get()(3); //=> 2
|
---|
| 260 | * Identity.of(identity).contramap(a => divide2(add1(a))).get()(3); //=> 2
|
---|
| 261 | */
|
---|
| 262 | }, {
|
---|
| 263 | key: _fl$contramap,
|
---|
| 264 | value: function value(fn) {
|
---|
| 265 | var _this = this;
|
---|
| 266 | return this.constructor.of(function (value) {
|
---|
| 267 | return _this.value(fn(value));
|
---|
| 268 | });
|
---|
| 269 | }
|
---|
| 270 | }, {
|
---|
| 271 | key: "contramap",
|
---|
| 272 | value: function contramap(fn) {
|
---|
| 273 | return this[fl.contramap](fn);
|
---|
| 274 | }
|
---|
| 275 | }], [{
|
---|
| 276 | key: _fl$of,
|
---|
| 277 | value:
|
---|
| 278 | /**
|
---|
| 279 | * Fantasy land {@link https://github.com/fantasyland/fantasy-land#applicative|Applicative} specification.
|
---|
| 280 | *
|
---|
| 281 | * @static
|
---|
| 282 | * @sig of :: Applicative f => a -> f a
|
---|
| 283 | * @param {*} value
|
---|
| 284 | * @returns {RA.Identity}
|
---|
| 285 | * @example
|
---|
| 286 | *
|
---|
| 287 | * const a = Identity.of(1); //=> Identity(1)
|
---|
| 288 | */
|
---|
| 289 | function value(_value) {
|
---|
| 290 | return new Identity(_value);
|
---|
| 291 | }
|
---|
| 292 | }, {
|
---|
| 293 | key: "of",
|
---|
| 294 | value: function of(value) {
|
---|
| 295 | return new Identity(value);
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | /**
|
---|
| 299 | * @static
|
---|
| 300 | */
|
---|
| 301 | }, {
|
---|
| 302 | key: '@@type',
|
---|
| 303 | get: function get() {
|
---|
| 304 | return 'RA/Identity';
|
---|
| 305 | }
|
---|
| 306 | }]);
|
---|
| 307 | return Identity;
|
---|
| 308 | }(fl.of, fl.ap, fl.map, fl.equals, fl.concat, fl.chain, fl.lte, fl.empty, fl.contramap);
|
---|
| 309 | var _default = Identity;
|
---|
| 310 | exports["default"] = _default; |
---|