infestines.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.I = {})));
  5. }(this, (function (exports) { 'use strict';
  6. var AP = 'ap';
  7. var CHAIN = 'chain';
  8. var MAP = 'map';
  9. var OF = 'of';
  10. var FANTASY_LAND_SLASH = 'fantasy-land/';
  11. var FANTASY_LAND_SLASH_OF = FANTASY_LAND_SLASH + OF;
  12. var FANTASY_LAND_SLASH_MAP = FANTASY_LAND_SLASH + MAP;
  13. var FANTASY_LAND_SLASH_AP = FANTASY_LAND_SLASH + AP;
  14. var FANTASY_LAND_SLASH_CHAIN = FANTASY_LAND_SLASH + CHAIN;
  15. var CONSTRUCTOR = 'constructor';
  16. var PROTOTYPE = 'prototype';
  17. //
  18. var id = function id(x) {
  19. return x;
  20. };
  21. //
  22. function _defineNameU(fn, value) {
  23. return Object.defineProperty(fn, 'name', { value: value, configurable: true });
  24. }
  25. var defineNameU = /*#__PURE__*/function () {
  26. try {
  27. return _defineNameU(_defineNameU, 'defineName');
  28. } catch (_) {
  29. return function (fn, _) {
  30. return fn;
  31. };
  32. }
  33. }();
  34. //
  35. var setName = function (to, name) {
  36. return defineNameU(to, name);
  37. };
  38. var copyName = function (to, from) {
  39. return defineNameU(to, from.name);
  40. };
  41. var withName = function (ary) {
  42. return function (fn) {
  43. return copyName(ary(fn), fn);
  44. };
  45. };
  46. //
  47. var ary1of2 = /*#__PURE__*/withName(function (fn) {
  48. return function (x0, x1) {
  49. return arguments.length < 2 ? fn(x0) : fn(x0)(x1);
  50. };
  51. });
  52. var ary2of2 = /*#__PURE__*/withName(function (fn) {
  53. return function (x0, x1) {
  54. return arguments.length < 2 ? copyName(function (x1) {
  55. return fn(x0, x1);
  56. }, fn) : fn(x0, x1);
  57. };
  58. });
  59. var ary1of3 = /*#__PURE__*/withName(function (fn) {
  60. return function (x0, x1, x2) {
  61. switch (arguments.length) {
  62. case 0:
  63. case 1:
  64. return curryN(2, fn(x0));
  65. case 2:
  66. return curryN(2, fn(x0))(x1);
  67. default:
  68. return curryN(2, fn(x0))(x1, x2);
  69. }
  70. };
  71. });
  72. var ary2of3 = /*#__PURE__*/withName(function (fn) {
  73. return function (x0, x1, x2) {
  74. switch (arguments.length) {
  75. case 0:
  76. case 1:
  77. return ary1of2(copyName(function (x1) {
  78. return fn(x0, x1);
  79. }, fn));
  80. case 2:
  81. return fn(x0, x1);
  82. default:
  83. return fn(x0, x1)(x2);
  84. }
  85. };
  86. });
  87. var ary3of3 = /*#__PURE__*/withName(function (fn) {
  88. return function (x0, x1, x2) {
  89. switch (arguments.length) {
  90. case 0:
  91. case 1:
  92. return ary2of2(copyName(function (x1, x2) {
  93. return fn(x0, x1, x2);
  94. }, fn));
  95. case 2:
  96. return copyName(function (x2) {
  97. return fn(x0, x1, x2);
  98. }, fn);
  99. default:
  100. return fn(x0, x1, x2);
  101. }
  102. };
  103. });
  104. var ary1of4 = /*#__PURE__*/withName(function (fn) {
  105. return function (x0, x1, x2, x3) {
  106. switch (arguments.length) {
  107. case 0:
  108. case 1:
  109. return curryN(3, fn(x0));
  110. case 2:
  111. return curryN(3, fn(x0))(x1);
  112. case 3:
  113. return curryN(3, fn(x0))(x1, x2);
  114. default:
  115. return curryN(3, fn(x0))(x1, x2, x3);
  116. }
  117. };
  118. });
  119. var ary2of4 = /*#__PURE__*/withName(function (fn) {
  120. return function (x0, x1, x2, x3) {
  121. switch (arguments.length) {
  122. case 0:
  123. case 1:
  124. return ary1of3(copyName(function (x1) {
  125. return fn(x0, x1);
  126. }, fn));
  127. case 2:
  128. return curryN(2, fn(x0, x1));
  129. case 3:
  130. return curryN(2, fn(x0, x1))(x2);
  131. default:
  132. return curryN(2, fn(x0, x1))(x2, x3);
  133. }
  134. };
  135. });
  136. var ary3of4 = /*#__PURE__*/withName(function (fn) {
  137. return function (x0, x1, x2, x3) {
  138. switch (arguments.length) {
  139. case 0:
  140. case 1:
  141. return ary2of3(copyName(function (x1, x2) {
  142. return fn(x0, x1, x2);
  143. }, fn));
  144. case 2:
  145. return ary1of2(copyName(function (x2) {
  146. return fn(x0, x1, x2);
  147. }, fn));
  148. case 3:
  149. return fn(x0, x1, x2);
  150. default:
  151. return fn(x0, x1, x2)(x3);
  152. }
  153. };
  154. });
  155. var ary4of4 = /*#__PURE__*/withName(function (fn) {
  156. return function (x0, x1, x2, x3) {
  157. switch (arguments.length) {
  158. case 0:
  159. case 1:
  160. return ary3of3(copyName(function (x1, x2, x3) {
  161. return fn(x0, x1, x2, x3);
  162. }, fn));
  163. case 2:
  164. return ary2of2(copyName(function (x2, x3) {
  165. return fn(x0, x1, x2, x3);
  166. }, fn));
  167. case 3:
  168. return copyName(function (x3) {
  169. return fn(x0, x1, x2, x3);
  170. }, fn);
  171. default:
  172. return fn(x0, x1, x2, x3);
  173. }
  174. };
  175. });
  176. var ary0of0 = function ary0of0(fn) {
  177. return fn.length === 0 ? fn : copyName(function () {
  178. return fn();
  179. }, fn);
  180. };
  181. var ary1of1 = function ary1of1(fn) {
  182. return fn.length === 1 ? fn : copyName(function (x) {
  183. return fn(x);
  184. }, fn);
  185. };
  186. var C = [[ary0of0], [ary1of1, ary1of1], [void 0, ary1of2, ary2of2], [void 0, ary1of3, ary2of3, ary3of3], [void 0, ary1of4, ary2of4, ary3of4, ary4of4]];
  187. var curryN = function curryN(n, f) {
  188. return C[n][Math.min(n, f.length)](f);
  189. };
  190. var arityN = function arityN(n, f) {
  191. return C[n][n](f);
  192. };
  193. var curry = function curry(f) {
  194. return arityN(f.length, f);
  195. };
  196. //
  197. var create = Object.create;
  198. var assign = Object.assign;
  199. var toObject = function toObject(x) {
  200. return assign({}, x);
  201. };
  202. //
  203. var always = function always(x) {
  204. return function (_) {
  205. return x;
  206. };
  207. };
  208. var applyU = function apply(x2y, x) {
  209. return x2y(x);
  210. };
  211. var sndU = function snd(_, y) {
  212. return y;
  213. };
  214. //
  215. var freeze = function freeze(x) {
  216. return x && Object.freeze(x);
  217. };
  218. var freezeInDev = freeze;
  219. var array0 = /*#__PURE__*/freeze([]);
  220. var object0 = /*#__PURE__*/freeze({});
  221. //
  222. var isDefined = function isDefined(x) {
  223. return void 0 !== x;
  224. };
  225. //
  226. var hasOwnProperty = Object[PROTOTYPE].hasOwnProperty;
  227. var hasU = function has(p, x) {
  228. return hasOwnProperty.call(x, p);
  229. };
  230. //
  231. var prototypeOf = function prototypeOf(x) {
  232. return null == x ? x : Object.getPrototypeOf(x);
  233. };
  234. var constructorOf = function constructorOf(x) {
  235. return null == x ? x : (hasU(CONSTRUCTOR, x) ? prototypeOf(x) : x)[CONSTRUCTOR];
  236. };
  237. //
  238. var isFunction = function isFunction(x) {
  239. return typeof x === 'function';
  240. };
  241. var isString = function isString(x) {
  242. return typeof x === 'string';
  243. };
  244. var isNumber = function isNumber(x) {
  245. return typeof x === 'number';
  246. };
  247. var isArray = Array.isArray;
  248. var object = /*#__PURE__*/prototypeOf({});
  249. var isObject = function isObject(x) {
  250. return null != x && typeof x === 'object' && (hasU(CONSTRUCTOR, x) ? prototypeOf(x) === object : x[CONSTRUCTOR] === Object);
  251. };
  252. //
  253. var isInstanceOfU = function isInstanceOf(C, x) {
  254. return x instanceof C;
  255. };
  256. //
  257. var pipe2U = function pipe2(fn1, fn2) {
  258. var n = fn1.length;
  259. return n === 1 ? function (x) {
  260. return fn2(fn1(x));
  261. } : arityN(n, function () {
  262. return fn2(fn1.apply(undefined, arguments));
  263. });
  264. };
  265. var compose2U = function compose2(fn1, fn2) {
  266. return pipe2U(fn2, fn1);
  267. };
  268. //
  269. function seq(x) {
  270. for (var _len = arguments.length, fns = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  271. fns[_key - 1] = arguments[_key];
  272. }
  273. for (var i = 0, n = fns.length; i < n; ++i) {
  274. x = fns[i](x);
  275. }return x;
  276. }
  277. function seqPartial(x) {
  278. for (var _len2 = arguments.length, fns = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  279. fns[_key2 - 1] = arguments[_key2];
  280. }
  281. for (var i = 0, n = fns.length; isDefined(x) && i < n; ++i) {
  282. x = fns[i](x);
  283. }return x;
  284. }
  285. //
  286. var identicalU = function identical(a, b) {
  287. return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
  288. };
  289. //
  290. var whereEqU = function whereEq(t, o) {
  291. for (var k in t) {
  292. var bk = o[k];
  293. if (!isDefined(bk) && !hasU(k, o) || !acyclicEqualsU(t[k], bk)) return false;
  294. }
  295. return true;
  296. };
  297. //
  298. var hasKeysOfU = function hasKeysOf(t, o) {
  299. for (var k in t) {
  300. if (!hasU(k, o)) return false;
  301. }return true;
  302. };
  303. //
  304. var acyclicEqualsObject = function acyclicEqualsObject(a, b) {
  305. return whereEqU(a, b) && hasKeysOfU(b, a);
  306. };
  307. function acyclicEqualsArray(a, b) {
  308. var n = a.length;
  309. if (n !== b.length) return false;
  310. for (var i = 0; i < n; ++i) {
  311. if (!acyclicEqualsU(a[i], b[i])) return false;
  312. }return true;
  313. }
  314. var acyclicEqualsU = function acyclicEquals(a, b) {
  315. if (identicalU(a, b)) return true;
  316. if (!a || !b) return false;
  317. var c = constructorOf(a);
  318. if (c !== constructorOf(b)) return false;
  319. switch (c) {
  320. case Array:
  321. return acyclicEqualsArray(a, b);
  322. case Object:
  323. return acyclicEqualsObject(a, b);
  324. default:
  325. return isFunction(a.equals) && a.equals(b);
  326. }
  327. };
  328. //
  329. var unzipObjIntoU = function unzipObjInto(o, ks, vs) {
  330. for (var k in o) {
  331. if (ks) ks.push(k);
  332. if (vs) vs.push(o[k]);
  333. }
  334. };
  335. function keys(o) {
  336. if (isInstanceOfU(Object, o)) {
  337. if (isObject(o)) {
  338. var ks = [];
  339. unzipObjIntoU(o, ks, 0);
  340. return ks;
  341. } else {
  342. return Object.keys(o);
  343. }
  344. }
  345. }
  346. function values(o) {
  347. if (isInstanceOfU(Object, o)) {
  348. if (isObject(o)) {
  349. var vs = [];
  350. unzipObjIntoU(o, 0, vs);
  351. return vs;
  352. } else {
  353. var xs = Object.keys(o);
  354. var n = xs.length;
  355. for (var i = 0; i < n; ++i) {
  356. xs[i] = o[xs[i]];
  357. }return xs;
  358. }
  359. }
  360. }
  361. //
  362. var assocPartialU = function assocPartial(k, v, o) {
  363. var r = {};
  364. if (o instanceof Object) {
  365. if (!isObject(o)) o = toObject(o);
  366. for (var l in o) {
  367. if (l !== k) {
  368. r[l] = o[l];
  369. } else {
  370. r[k] = v;
  371. k = void 0;
  372. }
  373. }
  374. }
  375. if (isDefined(k)) r[k] = v;
  376. return r;
  377. };
  378. var dissocPartialU = function dissocPartial(k, o) {
  379. var r = void 0;
  380. if (o instanceof Object) {
  381. if (!isObject(o)) o = toObject(o);
  382. for (var l in o) {
  383. if (l !== k) {
  384. if (!r) r = {};
  385. r[l] = o[l];
  386. } else {
  387. k = void 0;
  388. }
  389. }
  390. }
  391. return r;
  392. };
  393. //
  394. var inherit = function inherit(Derived, Base, protos, statics) {
  395. return assign(Derived[PROTOTYPE] = create(Base[PROTOTYPE]), protos)[CONSTRUCTOR] = assign(Derived, statics);
  396. };
  397. //
  398. function Functor(map) {
  399. if (!isInstanceOfU(Functor, this)) return freezeInDev(new Functor(map));
  400. this[MAP] = map;
  401. }
  402. var Applicative = /*#__PURE__*/inherit(function Applicative(map, of, ap) {
  403. if (!isInstanceOfU(Applicative, this)) return freezeInDev(new Applicative(map, of, ap));
  404. Functor.call(this, map);
  405. this[OF] = of;
  406. this[AP] = ap;
  407. }, Functor);
  408. var Monad = /*#__PURE__*/inherit(function Monad(map, of, ap, chain) {
  409. if (!isInstanceOfU(Monad, this)) return freezeInDev(new Monad(map, of, ap, chain));
  410. Applicative.call(this, map, of, ap);
  411. this[CHAIN] = chain;
  412. }, Applicative);
  413. //
  414. var Identity = /*#__PURE__*/Monad(applyU, id, applyU, applyU);
  415. var IdentityOrU = function IdentityOr(isOther, other) {
  416. var map = other[MAP];
  417. var ap = other[AP];
  418. var of = other[OF];
  419. var chain = other[CHAIN];
  420. var mapEither = function mapEither(xy, xM) {
  421. return isOther(xM) ? map(xy, xM) : xy(xM);
  422. };
  423. var toOther = function toOther(x) {
  424. return isOther(x) ? x : of(x);
  425. };
  426. return Monad(mapEither, id, function apEither(xyM, xM) {
  427. return isOther(xyM) ? isOther(xM) ? ap(xyM, xM) : map(function (xy) {
  428. return xy(xM);
  429. }, xyM) : mapEither(xyM, xM);
  430. }, function chainEither(xyM, xM) {
  431. return isOther(xM) ? chain(function (x) {
  432. return toOther(xyM(x));
  433. }, xM) : xyM(xM);
  434. });
  435. };
  436. //
  437. var isThenable = function isThenable(xP) {
  438. return null != xP && isFunction(xP.then);
  439. };
  440. var thenU = function then(xyP, xP) {
  441. return xP.then(xyP);
  442. };
  443. var resolve = function resolve(x) {
  444. return Promise.resolve(x);
  445. };
  446. var Async = /*#__PURE__*/Monad(thenU, resolve, function apAsync(xyP, xP) {
  447. return thenU(function (xy) {
  448. return thenU(xy, xP);
  449. }, xyP);
  450. }, thenU);
  451. var IdentityAsync = /*#__PURE__*/IdentityOrU(isThenable, Async);
  452. //
  453. var fantasyBop = function fantasyBop(m) {
  454. return setName(function (f, x) {
  455. return x[m](f);
  456. }, m);
  457. };
  458. var fantasyMap = /*#__PURE__*/fantasyBop(FANTASY_LAND_SLASH_MAP);
  459. var fantasyAp = /*#__PURE__*/fantasyBop(FANTASY_LAND_SLASH_AP);
  460. var fantasyChain = /*#__PURE__*/fantasyBop(FANTASY_LAND_SLASH_CHAIN);
  461. var FantasyFunctor = /*#__PURE__*/Functor(fantasyMap);
  462. var fromFantasyApplicative = function fromFantasyApplicative(Type) {
  463. return Applicative(fantasyMap, Type[FANTASY_LAND_SLASH_OF], fantasyAp);
  464. };
  465. var fromFantasyMonad = function fromFantasyMonad(Type) {
  466. return Monad(fantasyMap, Type[FANTASY_LAND_SLASH_OF], fantasyAp, fantasyChain);
  467. };
  468. var fromFantasy = function fromFantasy(Type) {
  469. return Type.prototype[FANTASY_LAND_SLASH_CHAIN] ? fromFantasyMonad(Type) : Type[FANTASY_LAND_SLASH_OF] ? fromFantasyApplicative(Type) : FantasyFunctor;
  470. };
  471. exports.id = id;
  472. exports.defineNameU = defineNameU;
  473. exports.curryN = curryN;
  474. exports.arityN = arityN;
  475. exports.curry = curry;
  476. exports.create = create;
  477. exports.assign = assign;
  478. exports.toObject = toObject;
  479. exports.always = always;
  480. exports.applyU = applyU;
  481. exports.sndU = sndU;
  482. exports.freeze = freeze;
  483. exports.array0 = array0;
  484. exports.object0 = object0;
  485. exports.isDefined = isDefined;
  486. exports.hasU = hasU;
  487. exports.prototypeOf = prototypeOf;
  488. exports.constructorOf = constructorOf;
  489. exports.isFunction = isFunction;
  490. exports.isString = isString;
  491. exports.isNumber = isNumber;
  492. exports.isArray = isArray;
  493. exports.isObject = isObject;
  494. exports.isInstanceOfU = isInstanceOfU;
  495. exports.pipe2U = pipe2U;
  496. exports.compose2U = compose2U;
  497. exports.seq = seq;
  498. exports.seqPartial = seqPartial;
  499. exports.identicalU = identicalU;
  500. exports.whereEqU = whereEqU;
  501. exports.hasKeysOfU = hasKeysOfU;
  502. exports.acyclicEqualsObject = acyclicEqualsObject;
  503. exports.acyclicEqualsU = acyclicEqualsU;
  504. exports.unzipObjIntoU = unzipObjIntoU;
  505. exports.keys = keys;
  506. exports.values = values;
  507. exports.assocPartialU = assocPartialU;
  508. exports.dissocPartialU = dissocPartialU;
  509. exports.inherit = inherit;
  510. exports.Functor = Functor;
  511. exports.Applicative = Applicative;
  512. exports.Monad = Monad;
  513. exports.Identity = Identity;
  514. exports.IdentityOrU = IdentityOrU;
  515. exports.isThenable = isThenable;
  516. exports.resolve = resolve;
  517. exports.Async = Async;
  518. exports.IdentityAsync = IdentityAsync;
  519. exports.FantasyFunctor = FantasyFunctor;
  520. exports.fromFantasyApplicative = fromFantasyApplicative;
  521. exports.fromFantasyMonad = fromFantasyMonad;
  522. exports.fromFantasy = fromFantasy;
  523. Object.defineProperty(exports, '__esModule', { value: true });
  524. })));