版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

816 строки
23 KiB

  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  14. if (k2 === undefined) k2 = k;
  15. var desc = Object.getOwnPropertyDescriptor(m, k);
  16. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  17. desc = { enumerable: true, get: function() { return m[k]; } };
  18. }
  19. Object.defineProperty(o, k2, desc);
  20. }) : (function(o, m, k, k2) {
  21. if (k2 === undefined) k2 = k;
  22. o[k2] = m[k];
  23. }));
  24. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  25. Object.defineProperty(o, "default", { enumerable: true, value: v });
  26. }) : function(o, v) {
  27. o["default"] = v;
  28. });
  29. var __importStar = (this && this.__importStar) || function (mod) {
  30. if (mod && mod.__esModule) return mod;
  31. var result = {};
  32. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  33. __setModuleDefault(result, mod);
  34. return result;
  35. };
  36. Object.defineProperty(exports, "__esModule", { value: true });
  37. exports.getTraversableWithIndex = exports.getFoldableWithIndex = exports.reduceRightWithIndex = exports.foldMapWithIndex = exports.reduceWithIndex = exports.getFoldable = exports.reduceRight = exports.foldMap = exports.reduce = exports.getWitherable = exports.getFilterableWithIndex = exports.getDifferenceMagma = exports.getIntersectionSemigroup = exports.getUnionMonoid = exports.getUnionSemigroup = exports.URI = exports.separate = exports.partitionMap = exports.partition = exports.mapWithIndex = exports.map = exports.filterMap = exports.filter = exports.compact = exports.filterWithIndex = exports.filterMapWithIndex = exports.partitionWithIndex = exports.partitionMapWithIndex = exports.fromFoldable = exports.singleton = exports.getMonoid = exports.getEq = exports.isSubmap = exports.lookup = exports.lookupWithKey = exports.pop = exports.modifyAt = exports.updateAt = exports.deleteAt = exports.upsertAt = exports.toUnfoldable = exports.toArray = exports.collect = exports.values = exports.keys = exports.elem = exports.member = exports.isEmpty = exports.size = exports.getShow = void 0;
  38. exports.map_ = exports.insertAt = exports.empty = exports.difference = exports.intersection = exports.union = exports.Filterable = exports.Compactable = exports.flap = exports.Functor = void 0;
  39. var function_1 = require("./function");
  40. var Functor_1 = require("./Functor");
  41. var _ = __importStar(require("./internal"));
  42. var O = __importStar(require("./Option"));
  43. var RM = __importStar(require("./ReadonlyMap"));
  44. var Separated_1 = require("./Separated");
  45. var Witherable_1 = require("./Witherable");
  46. /**
  47. * @category instances
  48. * @since 2.0.0
  49. */
  50. exports.getShow = RM.getShow;
  51. /**
  52. * Calculate the number of key/value pairs in a map
  53. *
  54. * @since 2.0.0
  55. */
  56. exports.size = RM.size;
  57. /**
  58. * Test whether or not a map is empty
  59. *
  60. * @since 2.0.0
  61. */
  62. exports.isEmpty = RM.isEmpty;
  63. // TODO: remove non-curried overloading in v3
  64. /**
  65. * Test whether or not a key exists in a map
  66. *
  67. * @since 2.0.0
  68. */
  69. exports.member = RM.member;
  70. // TODO: remove non-curried overloading in v3
  71. /**
  72. * Test whether or not a value is a member of a map
  73. *
  74. * @since 2.0.0
  75. */
  76. exports.elem = RM.elem;
  77. /**
  78. * Get a sorted `Array` of the keys contained in a `Map`.
  79. *
  80. * @since 2.0.0
  81. */
  82. var keys = function (O) {
  83. return function (m) {
  84. return Array.from(m.keys()).sort(O.compare);
  85. };
  86. };
  87. exports.keys = keys;
  88. /**
  89. * Get a sorted `Array` of the values contained in a `Map`.
  90. *
  91. * @since 2.0.0
  92. */
  93. var values = function (O) {
  94. return function (m) {
  95. return Array.from(m.values()).sort(O.compare);
  96. };
  97. };
  98. exports.values = values;
  99. /**
  100. * @since 2.0.0
  101. */
  102. function collect(O) {
  103. var keysO = (0, exports.keys)(O);
  104. return function (f) {
  105. return function (m) {
  106. var out = [];
  107. var ks = keysO(m);
  108. for (var _i = 0, ks_1 = ks; _i < ks_1.length; _i++) {
  109. var key = ks_1[_i];
  110. out.push(f(key, m.get(key)));
  111. }
  112. return out;
  113. };
  114. };
  115. }
  116. exports.collect = collect;
  117. /**
  118. * Get a sorted `Array` of the key/value pairs contained in a `Map`.
  119. *
  120. * @since 2.0.0
  121. */
  122. function toArray(O) {
  123. return collect(O)(function (k, a) { return [k, a]; });
  124. }
  125. exports.toArray = toArray;
  126. function toUnfoldable(ord, U) {
  127. var toArrayO = toArray(ord);
  128. return function (d) {
  129. var kas = toArrayO(d);
  130. var len = kas.length;
  131. return U.unfold(0, function (b) { return (b < len ? _.some([kas[b], b + 1]) : _.none); });
  132. };
  133. }
  134. exports.toUnfoldable = toUnfoldable;
  135. /**
  136. * Insert or replace a key/value pair in a `Map`.
  137. *
  138. * @since 2.0.0
  139. */
  140. var upsertAt = function (E) {
  141. var lookupWithKeyE = lookupWithKey(E);
  142. return function (k, a) {
  143. var lookupWithKeyEk = lookupWithKeyE(k);
  144. return function (m) {
  145. var found = lookupWithKeyEk(m);
  146. if (_.isNone(found)) {
  147. var out = new Map(m);
  148. out.set(k, a);
  149. return out;
  150. }
  151. else if (found.value[1] !== a) {
  152. var out = new Map(m);
  153. out.set(found.value[0], a);
  154. return out;
  155. }
  156. return m;
  157. };
  158. };
  159. };
  160. exports.upsertAt = upsertAt;
  161. /**
  162. * Delete a key and value from a map
  163. *
  164. * @since 2.0.0
  165. */
  166. var deleteAt = function (E) {
  167. var lookupWithKeyE = lookupWithKey(E);
  168. return function (k) { return function (m) {
  169. var found = lookupWithKeyE(k, m);
  170. if (_.isSome(found)) {
  171. var r = new Map(m);
  172. r.delete(found.value[0]);
  173. return r;
  174. }
  175. return m;
  176. }; };
  177. };
  178. exports.deleteAt = deleteAt;
  179. /**
  180. * @since 2.0.0
  181. */
  182. var updateAt = function (E) {
  183. var modifyAtE = (0, exports.modifyAt)(E);
  184. return function (k, a) { return modifyAtE(k, function () { return a; }); };
  185. };
  186. exports.updateAt = updateAt;
  187. /**
  188. * @since 2.0.0
  189. */
  190. var modifyAt = function (E) {
  191. var lookupWithKeyE = lookupWithKey(E);
  192. return function (k, f) { return function (m) {
  193. var found = lookupWithKeyE(k, m);
  194. if (_.isNone(found)) {
  195. return _.none;
  196. }
  197. var r = new Map(m);
  198. r.set(found.value[0], f(found.value[1]));
  199. return _.some(r);
  200. }; };
  201. };
  202. exports.modifyAt = modifyAt;
  203. /**
  204. * Delete a key and value from a map, returning the value as well as the subsequent map
  205. *
  206. * @since 2.0.0
  207. */
  208. function pop(E) {
  209. var lookupE = (0, exports.lookup)(E);
  210. var deleteAtE = (0, exports.deleteAt)(E);
  211. return function (k) {
  212. var deleteAtEk = deleteAtE(k);
  213. return function (m) {
  214. return (0, function_1.pipe)(lookupE(k, m), O.map(function (a) { return [a, deleteAtEk(m)]; }));
  215. };
  216. };
  217. }
  218. exports.pop = pop;
  219. function lookupWithKey(E) {
  220. return function (k, m) {
  221. if (m === undefined) {
  222. var lookupWithKeyE_1 = lookupWithKey(E);
  223. return function (m) { return lookupWithKeyE_1(k, m); };
  224. }
  225. var entries = m.entries();
  226. var e;
  227. while (!(e = entries.next()).done) {
  228. var _a = e.value, ka = _a[0], a = _a[1];
  229. if (E.equals(ka, k)) {
  230. return _.some([ka, a]);
  231. }
  232. }
  233. return _.none;
  234. };
  235. }
  236. exports.lookupWithKey = lookupWithKey;
  237. // TODO: remove non-curried overloading in v3
  238. /**
  239. * Lookup the value for a key in a `Map`.
  240. *
  241. * @since 2.0.0
  242. */
  243. exports.lookup = RM.lookup;
  244. // TODO: remove non-curried overloading in v3
  245. /**
  246. * Test whether or not one `Map` contains all of the keys and values contained in another `Map`
  247. *
  248. * @since 2.0.0
  249. */
  250. exports.isSubmap = RM.isSubmap;
  251. /**
  252. * @category instances
  253. * @since 2.0.0
  254. */
  255. exports.getEq = RM.getEq;
  256. /**
  257. * Gets `Monoid` instance for Maps given `Semigroup` instance for their values
  258. *
  259. * @category instances
  260. * @since 2.0.0
  261. */
  262. function getMonoid(SK, SA) {
  263. var lookupWithKeyS = lookupWithKey(SK);
  264. return {
  265. concat: function (mx, my) {
  266. if ((0, exports.isEmpty)(mx)) {
  267. return my;
  268. }
  269. if ((0, exports.isEmpty)(my)) {
  270. return mx;
  271. }
  272. var r = new Map(mx);
  273. var entries = my.entries();
  274. var e;
  275. while (!(e = entries.next()).done) {
  276. var _a = e.value, k = _a[0], a = _a[1];
  277. var mxOptA = lookupWithKeyS(k, mx);
  278. if (_.isSome(mxOptA)) {
  279. r.set(mxOptA.value[0], SA.concat(mxOptA.value[1], a));
  280. }
  281. else {
  282. r.set(k, a);
  283. }
  284. }
  285. return r;
  286. },
  287. empty: new Map()
  288. };
  289. }
  290. exports.getMonoid = getMonoid;
  291. /**
  292. * Create a map with one key/value pair
  293. *
  294. * @since 2.0.0
  295. */
  296. var singleton = function (k, a) { return new Map([[k, a]]); };
  297. exports.singleton = singleton;
  298. function fromFoldable(E, M, F) {
  299. return function (fka) {
  300. var lookupWithKeyE = lookupWithKey(E);
  301. return F.reduce(fka, new Map(), function (b, _a) {
  302. var k = _a[0], a = _a[1];
  303. var bOpt = lookupWithKeyE(k, b);
  304. if (_.isSome(bOpt)) {
  305. b.set(bOpt.value[0], M.concat(bOpt.value[1], a));
  306. }
  307. else {
  308. b.set(k, a);
  309. }
  310. return b;
  311. });
  312. };
  313. }
  314. exports.fromFoldable = fromFoldable;
  315. var _mapWithIndex = function (fa, f) {
  316. var m = new Map();
  317. var entries = fa.entries();
  318. var e;
  319. while (!(e = entries.next()).done) {
  320. var _a = e.value, key = _a[0], a = _a[1];
  321. m.set(key, f(key, a));
  322. }
  323. return m;
  324. };
  325. /**
  326. * @since 2.10.0
  327. */
  328. var partitionMapWithIndex = function (f) {
  329. return function (fa) {
  330. var left = new Map();
  331. var right = new Map();
  332. var entries = fa.entries();
  333. var e;
  334. while (!(e = entries.next()).done) {
  335. var _a = e.value, k = _a[0], a = _a[1];
  336. var ei = f(k, a);
  337. if (_.isLeft(ei)) {
  338. left.set(k, ei.left);
  339. }
  340. else {
  341. right.set(k, ei.right);
  342. }
  343. }
  344. return (0, Separated_1.separated)(left, right);
  345. };
  346. };
  347. exports.partitionMapWithIndex = partitionMapWithIndex;
  348. function partitionWithIndex(predicateWithIndex) {
  349. return function (fa) {
  350. var left = new Map();
  351. var right = new Map();
  352. var entries = fa.entries();
  353. var e;
  354. while (!(e = entries.next()).done) {
  355. var _a = e.value, k = _a[0], a = _a[1];
  356. if (predicateWithIndex(k, a)) {
  357. right.set(k, a);
  358. }
  359. else {
  360. left.set(k, a);
  361. }
  362. }
  363. return (0, Separated_1.separated)(left, right);
  364. };
  365. }
  366. exports.partitionWithIndex = partitionWithIndex;
  367. /**
  368. * @since 2.10.0
  369. */
  370. var filterMapWithIndex = function (f) {
  371. return function (fa) {
  372. var m = new Map();
  373. var entries = fa.entries();
  374. var e;
  375. while (!(e = entries.next()).done) {
  376. var _a = e.value, k = _a[0], a = _a[1];
  377. var o = f(k, a);
  378. if (_.isSome(o)) {
  379. m.set(k, o.value);
  380. }
  381. }
  382. return m;
  383. };
  384. };
  385. exports.filterMapWithIndex = filterMapWithIndex;
  386. function filterWithIndex(p) {
  387. return function (m) {
  388. var out = new Map();
  389. var entries = m.entries();
  390. var e;
  391. while (!(e = entries.next()).done) {
  392. var _a = e.value, k = _a[0], a = _a[1];
  393. if (p(k, a)) {
  394. out.set(k, a);
  395. }
  396. }
  397. return out;
  398. };
  399. }
  400. exports.filterWithIndex = filterWithIndex;
  401. var _map = function (fa, f) { return _mapWithIndex(fa, function (_, a) { return f(a); }); };
  402. var _filter = function (fa, p) {
  403. return _filterWithIndex(fa, function (_, a) { return p(a); });
  404. };
  405. var _filterMap = function (fa, f) { return _filterMapWithIndex(fa, function (_, a) { return f(a); }); };
  406. var _partition = function (fa, predicate) {
  407. return _partitionWithIndex(fa, function (_, a) { return predicate(a); });
  408. };
  409. var _partitionMap = function (fa, f) { return _partitionMapWithIndex(fa, function (_, a) { return f(a); }); };
  410. var _filterWithIndex = function (fa, p) { return (0, function_1.pipe)(fa, filterWithIndex(p)); };
  411. var _filterMapWithIndex = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.filterMapWithIndex)(f)); };
  412. var _partitionWithIndex = function (fa, p) { return (0, function_1.pipe)(fa, partitionWithIndex(p)); };
  413. var _partitionMapWithIndex = function (fa, f) {
  414. return (0, function_1.pipe)(fa, (0, exports.partitionMapWithIndex)(f));
  415. };
  416. /**
  417. * @category filtering
  418. * @since 2.0.0
  419. */
  420. var compact = function (fa) {
  421. var m = new Map();
  422. var entries = fa.entries();
  423. var e;
  424. while (!(e = entries.next()).done) {
  425. var _a = e.value, k = _a[0], oa = _a[1];
  426. if (_.isSome(oa)) {
  427. m.set(k, oa.value);
  428. }
  429. }
  430. return m;
  431. };
  432. exports.compact = compact;
  433. /**
  434. * @category filtering
  435. * @since 2.0.0
  436. */
  437. var filter = function (predicate) {
  438. return function (fa) {
  439. return _filter(fa, predicate);
  440. };
  441. };
  442. exports.filter = filter;
  443. /**
  444. * @category filtering
  445. * @since 2.0.0
  446. */
  447. var filterMap = function (f) { return function (fa) {
  448. return _filterMap(fa, f);
  449. }; };
  450. exports.filterMap = filterMap;
  451. /**
  452. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  453. * use the type constructor `F` to represent some computational context.
  454. *
  455. * @category mapping
  456. * @since 2.0.0
  457. */
  458. var map = function (f) { return function (fa) { return _map(fa, f); }; };
  459. exports.map = map;
  460. /**
  461. * @category mapping
  462. * @since 2.7.1
  463. */
  464. var mapWithIndex = function (f) { return function (fa) {
  465. return _mapWithIndex(fa, f);
  466. }; };
  467. exports.mapWithIndex = mapWithIndex;
  468. /**
  469. * @category filtering
  470. * @since 2.0.0
  471. */
  472. var partition = function (predicate) {
  473. return function (fa) {
  474. return _partition(fa, predicate);
  475. };
  476. };
  477. exports.partition = partition;
  478. /**
  479. * @category filtering
  480. * @since 2.0.0
  481. */
  482. var partitionMap = function (f) { return function (fa) { return _partitionMap(fa, f); }; };
  483. exports.partitionMap = partitionMap;
  484. /**
  485. * @category filtering
  486. * @since 2.0.0
  487. */
  488. var separate = function (fa) {
  489. var left = new Map();
  490. var right = new Map();
  491. var entries = fa.entries();
  492. var e;
  493. while (!(e = entries.next()).done) {
  494. var _a = e.value, k = _a[0], ei = _a[1];
  495. if (_.isLeft(ei)) {
  496. left.set(k, ei.left);
  497. }
  498. else {
  499. right.set(k, ei.right);
  500. }
  501. }
  502. return (0, Separated_1.separated)(left, right);
  503. };
  504. exports.separate = separate;
  505. /**
  506. * @category type lambdas
  507. * @since 2.0.0
  508. */
  509. exports.URI = 'Map';
  510. /**
  511. * @category instances
  512. * @since 2.11.0
  513. */
  514. var getUnionSemigroup = function (E, S) {
  515. var unionES = (0, exports.union)(E, S);
  516. return {
  517. concat: function (first, second) { return unionES(second)(first); }
  518. };
  519. };
  520. exports.getUnionSemigroup = getUnionSemigroup;
  521. /**
  522. * @category instances
  523. * @since 2.11.0
  524. */
  525. var getUnionMonoid = function (E, S) { return ({
  526. concat: (0, exports.getUnionSemigroup)(E, S).concat,
  527. empty: new Map()
  528. }); };
  529. exports.getUnionMonoid = getUnionMonoid;
  530. /**
  531. * @category instances
  532. * @since 2.11.0
  533. */
  534. var getIntersectionSemigroup = function (E, S) {
  535. var intersectionES = (0, exports.intersection)(E, S);
  536. return {
  537. concat: function (first, second) { return intersectionES(second)(first); }
  538. };
  539. };
  540. exports.getIntersectionSemigroup = getIntersectionSemigroup;
  541. /**
  542. * @category instances
  543. * @since 2.11.0
  544. */
  545. var getDifferenceMagma = function (E) {
  546. return function () {
  547. var differenceE = (0, exports.difference)(E);
  548. return {
  549. concat: function (first, second) { return differenceE(second)(first); }
  550. };
  551. };
  552. };
  553. exports.getDifferenceMagma = getDifferenceMagma;
  554. /**
  555. * @category filtering
  556. * @since 2.0.0
  557. */
  558. function getFilterableWithIndex() {
  559. return {
  560. URI: exports.URI,
  561. _E: undefined,
  562. map: _map,
  563. mapWithIndex: _mapWithIndex,
  564. compact: exports.compact,
  565. separate: exports.separate,
  566. filter: _filter,
  567. filterMap: _filterMap,
  568. partition: _partition,
  569. partitionMap: _partitionMap,
  570. partitionMapWithIndex: _partitionMapWithIndex,
  571. partitionWithIndex: _partitionWithIndex,
  572. filterMapWithIndex: _filterMapWithIndex,
  573. filterWithIndex: _filterWithIndex
  574. };
  575. }
  576. exports.getFilterableWithIndex = getFilterableWithIndex;
  577. /**
  578. * @category filtering
  579. * @since 2.0.0
  580. */
  581. function getWitherable(O) {
  582. var TWI = (0, exports.getTraversableWithIndex)(O);
  583. return {
  584. URI: exports.URI,
  585. _E: undefined,
  586. map: _map,
  587. compact: exports.compact,
  588. separate: exports.separate,
  589. filter: _filter,
  590. filterMap: _filterMap,
  591. partition: _partition,
  592. partitionMap: _partitionMap,
  593. reduce: TWI.reduce,
  594. foldMap: TWI.foldMap,
  595. reduceRight: TWI.reduceRight,
  596. traverse: TWI.traverse,
  597. sequence: TWI.sequence,
  598. mapWithIndex: _mapWithIndex,
  599. reduceWithIndex: TWI.reduceWithIndex,
  600. foldMapWithIndex: TWI.foldMapWithIndex,
  601. reduceRightWithIndex: TWI.reduceRightWithIndex,
  602. traverseWithIndex: TWI.traverseWithIndex,
  603. wilt: (0, Witherable_1.wiltDefault)(TWI, exports.Compactable),
  604. wither: (0, Witherable_1.witherDefault)(TWI, exports.Compactable)
  605. };
  606. }
  607. exports.getWitherable = getWitherable;
  608. /**
  609. * @category folding
  610. * @since 2.11.0
  611. */
  612. exports.reduce = RM.reduce;
  613. /**
  614. * @category folding
  615. * @since 2.11.0
  616. */
  617. exports.foldMap = RM.foldMap;
  618. /**
  619. * @category folding
  620. * @since 2.11.0
  621. */
  622. exports.reduceRight = RM.reduceRight;
  623. /**
  624. * @category folding
  625. * @since 2.11.0
  626. */
  627. var getFoldable = function (O) {
  628. return __assign(__assign({}, RM.getFoldable(O)), { URI: exports.URI });
  629. };
  630. exports.getFoldable = getFoldable;
  631. /**
  632. * @category folding
  633. * @since 2.11.0
  634. */
  635. exports.reduceWithIndex = RM.reduceWithIndex;
  636. /**
  637. * @category folding
  638. * @since 2.11.0
  639. */
  640. exports.foldMapWithIndex = RM.foldMapWithIndex;
  641. /**
  642. * @category folding
  643. * @since 2.11.0
  644. */
  645. exports.reduceRightWithIndex = RM.reduceRightWithIndex;
  646. /**
  647. * @category folding
  648. * @since 2.10.0
  649. */
  650. var getFoldableWithIndex = function (O) {
  651. return __assign(__assign({}, RM.getFoldableWithIndex(O)), { URI: exports.URI });
  652. };
  653. exports.getFoldableWithIndex = getFoldableWithIndex;
  654. /**
  655. * @category traversing
  656. * @since 2.10.0
  657. */
  658. var getTraversableWithIndex = function (O) {
  659. var FWI = (0, exports.getFoldableWithIndex)(O);
  660. var keysO = (0, exports.keys)(O);
  661. var traverseWithIndex = function (F) {
  662. return function (ta, f) {
  663. var fm = F.of(new Map());
  664. var ks = keysO(ta);
  665. var len = ks.length;
  666. var _loop_1 = function (i) {
  667. var key = ks[i];
  668. var a = ta.get(key);
  669. fm = F.ap(F.map(fm, function (m) { return function (b) { return m.set(key, b); }; }), f(key, a));
  670. };
  671. for (var i = 0; i < len; i++) {
  672. _loop_1(i);
  673. }
  674. return fm;
  675. };
  676. };
  677. var traverse = function (F) {
  678. var traverseWithIndexF = traverseWithIndex(F);
  679. return function (ta, f) { return traverseWithIndexF(ta, function (_, a) { return f(a); }); };
  680. };
  681. var sequence = function (F) {
  682. var traverseWithIndexF = traverseWithIndex(F);
  683. return function (ta) { return traverseWithIndexF(ta, function (_, a) { return a; }); };
  684. };
  685. return {
  686. URI: exports.URI,
  687. _E: undefined,
  688. map: _map,
  689. mapWithIndex: _mapWithIndex,
  690. reduce: FWI.reduce,
  691. foldMap: FWI.foldMap,
  692. reduceRight: FWI.reduceRight,
  693. reduceWithIndex: FWI.reduceWithIndex,
  694. foldMapWithIndex: FWI.foldMapWithIndex,
  695. reduceRightWithIndex: FWI.reduceRightWithIndex,
  696. traverse: traverse,
  697. sequence: sequence,
  698. traverseWithIndex: traverseWithIndex
  699. };
  700. };
  701. exports.getTraversableWithIndex = getTraversableWithIndex;
  702. /**
  703. * @category instances
  704. * @since 2.7.0
  705. */
  706. exports.Functor = {
  707. URI: exports.URI,
  708. map: _map
  709. };
  710. /**
  711. * @category mapping
  712. * @since 2.10.0
  713. */
  714. exports.flap = (0, Functor_1.flap)(exports.Functor);
  715. /**
  716. * @category instances
  717. * @since 2.7.0
  718. */
  719. exports.Compactable = {
  720. URI: exports.URI,
  721. compact: exports.compact,
  722. separate: exports.separate
  723. };
  724. /**
  725. * @category instances
  726. * @since 2.7.0
  727. */
  728. exports.Filterable = {
  729. URI: exports.URI,
  730. map: _map,
  731. compact: exports.compact,
  732. separate: exports.separate,
  733. filter: _filter,
  734. filterMap: _filterMap,
  735. partition: _partition,
  736. partitionMap: _partitionMap
  737. };
  738. // -------------------------------------------------------------------------------------
  739. // utils
  740. // -------------------------------------------------------------------------------------
  741. var copy = function (m) { return new Map(m); };
  742. /**
  743. * @since 2.11.0
  744. */
  745. var union = function (E, M) {
  746. var unionEM = RM.union(E, M);
  747. return function (second) { return function (first) {
  748. if ((0, exports.isEmpty)(first)) {
  749. return copy(second);
  750. }
  751. if ((0, exports.isEmpty)(second)) {
  752. return copy(first);
  753. }
  754. return unionEM(second)(first);
  755. }; };
  756. };
  757. exports.union = union;
  758. /**
  759. * @since 2.11.0
  760. */
  761. var intersection = function (E, M) {
  762. var intersectionEM = RM.intersection(E, M);
  763. return function (second) { return function (first) {
  764. if ((0, exports.isEmpty)(first) || (0, exports.isEmpty)(second)) {
  765. return new Map();
  766. }
  767. return intersectionEM(second)(first);
  768. }; };
  769. };
  770. exports.intersection = intersection;
  771. /**
  772. * @since 2.11.0
  773. */
  774. var difference = function (E) {
  775. var differenceE = RM.difference(E);
  776. return function (second) {
  777. return function (first) {
  778. if ((0, exports.isEmpty)(first)) {
  779. return copy(second);
  780. }
  781. if ((0, exports.isEmpty)(second)) {
  782. return copy(first);
  783. }
  784. return differenceE(second)(first);
  785. };
  786. };
  787. };
  788. exports.difference = difference;
  789. // -------------------------------------------------------------------------------------
  790. // deprecated
  791. // -------------------------------------------------------------------------------------
  792. /**
  793. * Use a `new Map()` instead.
  794. *
  795. * @category zone of death
  796. * @since 2.0.0
  797. * @deprecated
  798. */
  799. exports.empty = new Map();
  800. /**
  801. * Use [`upsertAt`](#upsertat) instead.
  802. *
  803. * @category zone of death
  804. * @since 2.0.0
  805. * @deprecated
  806. */
  807. exports.insertAt = exports.upsertAt;
  808. /**
  809. * Use [`Filterable`](#filterable) instead.
  810. *
  811. * @category zone of death
  812. * @since 2.0.0
  813. * @deprecated
  814. */
  815. exports.map_ = exports.Filterable;