版博士V2.0程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

1043 satır
30 KiB

  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.foldMap = exports.reduce = exports.Filterable = exports.Compactable = exports.getFunctorWithIndex = exports.flap = exports.Functor = 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.empty = exports.isSubmap = exports.lookup = exports.lookupWithKey = exports.pop = exports.modifyAt = exports.updateAt = exports.deleteAt = exports.upsertAt = exports.toUnfoldable = exports.toReadonlyArray = exports.collect = exports.values = exports.keys = exports.elem = exports.member = exports.isEmpty = exports.size = exports.getShow = exports.toMap = exports.fromMap = void 0;
  27. exports.readonlyMap = exports.insertAt = exports.difference = exports.intersection = exports.union = exports.getWitherable = exports.getTraversableWithIndex = exports.getTraversable = exports.getFoldableWithIndex = exports.reduceRightWithIndex = exports.foldMapWithIndex = exports.reduceWithIndex = exports.getFoldable = exports.reduceRight = void 0;
  28. var Eq_1 = require("./Eq");
  29. var function_1 = require("./function");
  30. var Functor_1 = require("./Functor");
  31. var _ = __importStar(require("./internal"));
  32. var O = __importStar(require("./Option"));
  33. var Separated_1 = require("./Separated");
  34. var Witherable_1 = require("./Witherable");
  35. /**
  36. * @category conversions
  37. * @since 2.5.0
  38. */
  39. var fromMap = function (m) { return new Map(m); };
  40. exports.fromMap = fromMap;
  41. /**
  42. * @category conversions
  43. * @since 2.5.0
  44. */
  45. function toMap(m) {
  46. return new Map(m);
  47. }
  48. exports.toMap = toMap;
  49. /**
  50. * @category instances
  51. * @since 2.5.0
  52. */
  53. function getShow(SK, SA) {
  54. return {
  55. show: function (m) {
  56. var entries = [];
  57. m.forEach(function (a, k) {
  58. entries.push("[".concat(SK.show(k), ", ").concat(SA.show(a), "]"));
  59. });
  60. return "new Map([".concat(entries.sort().join(', '), "])");
  61. }
  62. };
  63. }
  64. exports.getShow = getShow;
  65. /**
  66. * Calculate the number of key/value pairs in a map
  67. *
  68. * @since 2.5.0
  69. */
  70. var size = function (m) { return m.size; };
  71. exports.size = size;
  72. /**
  73. * Test whether or not a map is empty
  74. *
  75. * @since 2.5.0
  76. */
  77. var isEmpty = function (m) { return m.size === 0; };
  78. exports.isEmpty = isEmpty;
  79. function member(E) {
  80. var lookupE = lookup(E);
  81. return function (k, m) {
  82. if (m === undefined) {
  83. var memberE_1 = member(E);
  84. return function (m) { return memberE_1(k, m); };
  85. }
  86. return _.isSome(lookupE(k, m));
  87. };
  88. }
  89. exports.member = member;
  90. function elem(E) {
  91. return function (a, m) {
  92. if (m === undefined) {
  93. var elemE_1 = elem(E);
  94. return function (m) { return elemE_1(a, m); };
  95. }
  96. var values = m.values();
  97. var e;
  98. while (!(e = values.next()).done) {
  99. var v = e.value;
  100. if (E.equals(a, v)) {
  101. return true;
  102. }
  103. }
  104. return false;
  105. };
  106. }
  107. exports.elem = elem;
  108. /**
  109. * Get a sorted `ReadonlyArray` of the keys contained in a `ReadonlyMap`.
  110. *
  111. * @since 2.5.0
  112. */
  113. var keys = function (O) {
  114. return function (m) {
  115. return Array.from(m.keys()).sort(O.compare);
  116. };
  117. };
  118. exports.keys = keys;
  119. /**
  120. * Get a sorted `ReadonlyArray` of the values contained in a `ReadonlyMap`.
  121. *
  122. * @since 2.5.0
  123. */
  124. var values = function (O) {
  125. return function (m) {
  126. return Array.from(m.values()).sort(O.compare);
  127. };
  128. };
  129. exports.values = values;
  130. /**
  131. * @since 2.5.0
  132. */
  133. function collect(O) {
  134. var keysO = (0, exports.keys)(O);
  135. return function (f) {
  136. return function (m) {
  137. var out = [];
  138. var ks = keysO(m);
  139. for (var _i = 0, ks_1 = ks; _i < ks_1.length; _i++) {
  140. var key = ks_1[_i];
  141. out.push(f(key, m.get(key)));
  142. }
  143. return out;
  144. };
  145. };
  146. }
  147. exports.collect = collect;
  148. /**
  149. * Get a sorted `ReadonlyArray` of the key/value pairs contained in a `ReadonlyMap`.
  150. *
  151. * @category conversions
  152. * @since 2.5.0
  153. */
  154. var toReadonlyArray = function (O) {
  155. return collect(O)(function (k, a) { return [k, a]; });
  156. };
  157. exports.toReadonlyArray = toReadonlyArray;
  158. function toUnfoldable(ord, U) {
  159. var toReadonlyArrayO = (0, exports.toReadonlyArray)(ord);
  160. return function (d) {
  161. var kas = toReadonlyArrayO(d);
  162. var len = kas.length;
  163. return U.unfold(0, function (b) { return (b < len ? _.some([kas[b], b + 1]) : _.none); });
  164. };
  165. }
  166. exports.toUnfoldable = toUnfoldable;
  167. /**
  168. * Insert or replace a key/value pair in a `ReadonlyMap`.
  169. *
  170. * @since 2.10.0
  171. */
  172. var upsertAt = function (E) {
  173. var lookupWithKeyE = lookupWithKey(E);
  174. return function (k, a) {
  175. var lookupWithKeyEk = lookupWithKeyE(k);
  176. return function (m) {
  177. var found = lookupWithKeyEk(m);
  178. if (_.isNone(found)) {
  179. var out = new Map(m);
  180. out.set(k, a);
  181. return out;
  182. }
  183. else if (found.value[1] !== a) {
  184. var out = new Map(m);
  185. out.set(found.value[0], a);
  186. return out;
  187. }
  188. return m;
  189. };
  190. };
  191. };
  192. exports.upsertAt = upsertAt;
  193. /**
  194. * Delete a key and value from a map
  195. *
  196. * @since 2.5.0
  197. */
  198. var deleteAt = function (E) {
  199. var lookupWithKeyE = lookupWithKey(E);
  200. return function (k) { return function (m) {
  201. var found = lookupWithKeyE(k, m);
  202. if (_.isSome(found)) {
  203. var r = new Map(m);
  204. r.delete(found.value[0]);
  205. return r;
  206. }
  207. return m;
  208. }; };
  209. };
  210. exports.deleteAt = deleteAt;
  211. /**
  212. * @since 2.5.0
  213. */
  214. var updateAt = function (E) {
  215. var modifyAtE = (0, exports.modifyAt)(E);
  216. return function (k, a) { return modifyAtE(k, function () { return a; }); };
  217. };
  218. exports.updateAt = updateAt;
  219. /**
  220. * @since 2.5.0
  221. */
  222. var modifyAt = function (E) {
  223. var lookupWithKeyE = lookupWithKey(E);
  224. return function (k, f) { return function (m) {
  225. var found = lookupWithKeyE(k, m);
  226. if (_.isNone(found)) {
  227. return _.none;
  228. }
  229. var _a = found.value, fk = _a[0], fv = _a[1];
  230. var next = f(fv);
  231. if (next === fv) {
  232. return _.some(m);
  233. }
  234. var r = new Map(m);
  235. r.set(fk, next);
  236. return _.some(r);
  237. }; };
  238. };
  239. exports.modifyAt = modifyAt;
  240. /**
  241. * Delete a key and value from a map, returning the value as well as the subsequent map
  242. *
  243. * @since 2.5.0
  244. */
  245. function pop(E) {
  246. var lookupE = lookup(E);
  247. var deleteAtE = (0, exports.deleteAt)(E);
  248. return function (k) {
  249. var deleteAtEk = deleteAtE(k);
  250. return function (m) {
  251. return (0, function_1.pipe)(lookupE(k, m), O.map(function (a) { return [a, deleteAtEk(m)]; }));
  252. };
  253. };
  254. }
  255. exports.pop = pop;
  256. function lookupWithKey(E) {
  257. return function (k, m) {
  258. if (m === undefined) {
  259. var lookupWithKeyE_1 = lookupWithKey(E);
  260. return function (m) { return lookupWithKeyE_1(k, m); };
  261. }
  262. var entries = m.entries();
  263. var e;
  264. while (!(e = entries.next()).done) {
  265. var _a = e.value, ka = _a[0], a = _a[1];
  266. if (E.equals(ka, k)) {
  267. return _.some([ka, a]);
  268. }
  269. }
  270. return _.none;
  271. };
  272. }
  273. exports.lookupWithKey = lookupWithKey;
  274. function lookup(E) {
  275. var lookupWithKeyE = lookupWithKey(E);
  276. return function (k, m) {
  277. if (m === undefined) {
  278. var lookupE_1 = lookup(E);
  279. return function (m) { return lookupE_1(k, m); };
  280. }
  281. return (0, function_1.pipe)(lookupWithKeyE(k, m), O.map(function (_a) {
  282. var _ = _a[0], a = _a[1];
  283. return a;
  284. }));
  285. };
  286. }
  287. exports.lookup = lookup;
  288. function isSubmap(SK, SA) {
  289. var lookupWithKeyS = lookupWithKey(SK);
  290. return function (me, that) {
  291. if (that === undefined) {
  292. var isSubmapSKSA_1 = isSubmap(SK, SA);
  293. return function (that) { return isSubmapSKSA_1(that, me); };
  294. }
  295. var entries = me.entries();
  296. var e;
  297. while (!(e = entries.next()).done) {
  298. var _a = e.value, k = _a[0], a = _a[1];
  299. var d2OptA = lookupWithKeyS(k, that);
  300. if (_.isNone(d2OptA) || !SK.equals(k, d2OptA.value[0]) || !SA.equals(a, d2OptA.value[1])) {
  301. return false;
  302. }
  303. }
  304. return true;
  305. };
  306. }
  307. exports.isSubmap = isSubmap;
  308. /**
  309. * @since 2.5.0
  310. */
  311. exports.empty =
  312. // the type annotation here is intended (otherwise it doesn't type-check)
  313. new Map();
  314. /**
  315. * @category instances
  316. * @since 2.5.0
  317. */
  318. function getEq(SK, SA) {
  319. var isSubmapSKSA = isSubmap(SK, SA);
  320. return (0, Eq_1.fromEquals)(function (x, y) { return isSubmapSKSA(x, y) && isSubmapSKSA(y, x); });
  321. }
  322. exports.getEq = getEq;
  323. /**
  324. * Gets `Monoid` instance for Maps given `Semigroup` instance for their values
  325. *
  326. * @category instances
  327. * @since 2.5.0
  328. */
  329. function getMonoid(SK, SA) {
  330. var lookupWithKeyS = lookupWithKey(SK);
  331. return {
  332. concat: function (mx, my) {
  333. if ((0, exports.isEmpty)(mx)) {
  334. return my;
  335. }
  336. if ((0, exports.isEmpty)(my)) {
  337. return mx;
  338. }
  339. var r = new Map(mx);
  340. var entries = my.entries();
  341. var e;
  342. while (!(e = entries.next()).done) {
  343. var _a = e.value, k = _a[0], a = _a[1];
  344. var mxOptA = lookupWithKeyS(k, mx);
  345. if (_.isSome(mxOptA)) {
  346. r.set(mxOptA.value[0], SA.concat(mxOptA.value[1], a));
  347. }
  348. else {
  349. r.set(k, a);
  350. }
  351. }
  352. return r;
  353. },
  354. empty: exports.empty
  355. };
  356. }
  357. exports.getMonoid = getMonoid;
  358. /**
  359. * Create a map with one key/value pair
  360. *
  361. * @category constructors
  362. * @since 2.5.0
  363. */
  364. var singleton = function (k, a) { return new Map([[k, a]]); };
  365. exports.singleton = singleton;
  366. function fromFoldable(E, M, F) {
  367. return function (fka) {
  368. var lookupWithKeyE = lookupWithKey(E);
  369. return F.reduce(fka, new Map(), function (b, _a) {
  370. var k = _a[0], a = _a[1];
  371. var bOpt = lookupWithKeyE(k, b);
  372. if (_.isSome(bOpt)) {
  373. b.set(bOpt.value[0], M.concat(bOpt.value[1], a));
  374. }
  375. else {
  376. b.set(k, a);
  377. }
  378. return b;
  379. });
  380. };
  381. }
  382. exports.fromFoldable = fromFoldable;
  383. var _mapWithIndex = function (fa, f) {
  384. var m = new Map();
  385. var entries = fa.entries();
  386. var e;
  387. while (!(e = entries.next()).done) {
  388. var _a = e.value, key = _a[0], a = _a[1];
  389. m.set(key, f(key, a));
  390. }
  391. return m;
  392. };
  393. /**
  394. * @since 2.10.0
  395. */
  396. var partitionMapWithIndex = function (f) {
  397. return function (fa) {
  398. var left = new Map();
  399. var right = new Map();
  400. var entries = fa.entries();
  401. var e;
  402. while (!(e = entries.next()).done) {
  403. var _a = e.value, k = _a[0], a = _a[1];
  404. var ei = f(k, a);
  405. if (_.isLeft(ei)) {
  406. left.set(k, ei.left);
  407. }
  408. else {
  409. right.set(k, ei.right);
  410. }
  411. }
  412. return (0, Separated_1.separated)(left, right);
  413. };
  414. };
  415. exports.partitionMapWithIndex = partitionMapWithIndex;
  416. function partitionWithIndex(predicateWithIndex) {
  417. return function (m) {
  418. var left = new Map();
  419. var right = new Map();
  420. var entries = m.entries();
  421. var e;
  422. while (!(e = entries.next()).done) {
  423. var _a = e.value, k = _a[0], a = _a[1];
  424. if (predicateWithIndex(k, a)) {
  425. right.set(k, a);
  426. }
  427. else {
  428. left.set(k, a);
  429. }
  430. }
  431. return (0, Separated_1.separated)(left, right);
  432. };
  433. }
  434. exports.partitionWithIndex = partitionWithIndex;
  435. /**
  436. * @since 2.10.0
  437. */
  438. var filterMapWithIndex = function (f) {
  439. return function (fa) {
  440. var m = new Map();
  441. var entries = fa.entries();
  442. var e;
  443. while (!(e = entries.next()).done) {
  444. var _a = e.value, k = _a[0], a = _a[1];
  445. var o = f(k, a);
  446. if (_.isSome(o)) {
  447. m.set(k, o.value);
  448. }
  449. }
  450. return m;
  451. };
  452. };
  453. exports.filterMapWithIndex = filterMapWithIndex;
  454. function filterWithIndex(predicateWithIndex) {
  455. return function (m) {
  456. var out = new Map();
  457. var entries = m.entries();
  458. var e;
  459. while (!(e = entries.next()).done) {
  460. var _a = e.value, k = _a[0], a = _a[1];
  461. if (predicateWithIndex(k, a)) {
  462. out.set(k, a);
  463. }
  464. }
  465. return out;
  466. };
  467. }
  468. exports.filterWithIndex = filterWithIndex;
  469. var _map = function (fa, f) { return _mapWithIndex(fa, function (_, a) { return f(a); }); };
  470. var _filter = function (fa, p) {
  471. return _filterWithIndex(fa, function (_, a) { return p(a); });
  472. };
  473. var _filterMap = function (fa, f) { return _filterMapWithIndex(fa, function (_, a) { return f(a); }); };
  474. var _partition = function (fa, predicate) {
  475. return _partitionWithIndex(fa, function (_, a) { return predicate(a); });
  476. };
  477. var _partitionMap = function (fa, f) { return _partitionMapWithIndex(fa, function (_, a) { return f(a); }); };
  478. var _filterWithIndex = function (fa, p) { return (0, function_1.pipe)(fa, filterWithIndex(p)); };
  479. var _filterMapWithIndex = function (fa, f) {
  480. return (0, function_1.pipe)(fa, (0, exports.filterMapWithIndex)(f));
  481. };
  482. var _partitionWithIndex = function (fa, p) { return (0, function_1.pipe)(fa, partitionWithIndex(p)); };
  483. var _partitionMapWithIndex = function (fa, f) {
  484. return (0, function_1.pipe)(fa, (0, exports.partitionMapWithIndex)(f));
  485. };
  486. /**
  487. * @category filtering
  488. * @since 2.5.0
  489. */
  490. var compact = function (fa) {
  491. var m = new Map();
  492. var entries = fa.entries();
  493. var e;
  494. while (!(e = entries.next()).done) {
  495. var _a = e.value, k = _a[0], oa = _a[1];
  496. if (_.isSome(oa)) {
  497. m.set(k, oa.value);
  498. }
  499. }
  500. return m;
  501. };
  502. exports.compact = compact;
  503. /**
  504. * @category filtering
  505. * @since 2.5.0
  506. */
  507. var filter = function (predicate) {
  508. return function (fa) {
  509. return _filter(fa, predicate);
  510. };
  511. };
  512. exports.filter = filter;
  513. /**
  514. * @category filtering
  515. * @since 2.5.0
  516. */
  517. var filterMap = function (f) { return function (fa) {
  518. return _filterMap(fa, f);
  519. }; };
  520. exports.filterMap = filterMap;
  521. /**
  522. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  523. * use the type constructor `F` to represent some computational context.
  524. *
  525. * @category mapping
  526. * @since 2.5.0
  527. */
  528. var map = function (f) { return function (fa) { return _map(fa, f); }; };
  529. exports.map = map;
  530. /**
  531. * @category mapping
  532. * @since 2.7.1
  533. */
  534. var mapWithIndex = function (f) { return function (fa) {
  535. return _mapWithIndex(fa, f);
  536. }; };
  537. exports.mapWithIndex = mapWithIndex;
  538. /**
  539. * @category filtering
  540. * @since 2.5.0
  541. */
  542. var partition = function (predicate) {
  543. return function (fa) {
  544. return _partition(fa, predicate);
  545. };
  546. };
  547. exports.partition = partition;
  548. /**
  549. * @category filtering
  550. * @since 2.5.0
  551. */
  552. var partitionMap = function (f) { return function (fa) { return _partitionMap(fa, f); }; };
  553. exports.partitionMap = partitionMap;
  554. /**
  555. * @category filtering
  556. * @since 2.5.0
  557. */
  558. var separate = function (fa) {
  559. var left = new Map();
  560. var right = new Map();
  561. var entries = fa.entries();
  562. var e;
  563. while (!(e = entries.next()).done) {
  564. var _a = e.value, k = _a[0], ei = _a[1];
  565. if (_.isLeft(ei)) {
  566. left.set(k, ei.left);
  567. }
  568. else {
  569. right.set(k, ei.right);
  570. }
  571. }
  572. return (0, Separated_1.separated)(left, right);
  573. };
  574. exports.separate = separate;
  575. /**
  576. * @category type lambdas
  577. * @since 2.5.0
  578. */
  579. exports.URI = 'ReadonlyMap';
  580. /**
  581. * @category instances
  582. * @since 2.11.0
  583. */
  584. var getUnionSemigroup = function (E, S) {
  585. var unionES = (0, exports.union)(E, S);
  586. return {
  587. concat: function (first, second) { return unionES(second)(first); }
  588. };
  589. };
  590. exports.getUnionSemigroup = getUnionSemigroup;
  591. /**
  592. * @category instances
  593. * @since 2.11.0
  594. */
  595. var getUnionMonoid = function (E, S) { return ({
  596. concat: (0, exports.getUnionSemigroup)(E, S).concat,
  597. empty: exports.empty
  598. }); };
  599. exports.getUnionMonoid = getUnionMonoid;
  600. /**
  601. * @category instances
  602. * @since 2.11.0
  603. */
  604. var getIntersectionSemigroup = function (E, S) {
  605. var intersectionES = (0, exports.intersection)(E, S);
  606. return {
  607. concat: function (first, second) { return intersectionES(second)(first); }
  608. };
  609. };
  610. exports.getIntersectionSemigroup = getIntersectionSemigroup;
  611. /**
  612. * @category instances
  613. * @since 2.11.0
  614. */
  615. var getDifferenceMagma = function (E) {
  616. return function () {
  617. var differenceE = (0, exports.difference)(E);
  618. return {
  619. concat: function (first, second) { return differenceE(second)(first); }
  620. };
  621. };
  622. };
  623. exports.getDifferenceMagma = getDifferenceMagma;
  624. /**
  625. * @category filtering
  626. * @since 2.5.0
  627. */
  628. function getFilterableWithIndex() {
  629. return {
  630. URI: exports.URI,
  631. _E: undefined,
  632. map: _map,
  633. mapWithIndex: _mapWithIndex,
  634. compact: exports.compact,
  635. separate: exports.separate,
  636. filter: _filter,
  637. filterMap: _filterMap,
  638. partition: _partition,
  639. partitionMap: _partitionMap,
  640. partitionMapWithIndex: _partitionMapWithIndex,
  641. partitionWithIndex: _partitionWithIndex,
  642. filterMapWithIndex: _filterMapWithIndex,
  643. filterWithIndex: _filterWithIndex
  644. };
  645. }
  646. exports.getFilterableWithIndex = getFilterableWithIndex;
  647. /**
  648. * @category instances
  649. * @since 2.7.0
  650. */
  651. exports.Functor = {
  652. URI: exports.URI,
  653. map: _map
  654. };
  655. /**
  656. * @category mapping
  657. * @since 2.10.0
  658. */
  659. exports.flap = (0, Functor_1.flap)(exports.Functor);
  660. /**
  661. * @category instances
  662. * @since 2.10.0
  663. */
  664. var getFunctorWithIndex = function () { return ({
  665. URI: exports.URI,
  666. _E: undefined,
  667. map: _map,
  668. mapWithIndex: _mapWithIndex
  669. }); };
  670. exports.getFunctorWithIndex = getFunctorWithIndex;
  671. /**
  672. * @category instances
  673. * @since 2.7.0
  674. */
  675. exports.Compactable = {
  676. URI: exports.URI,
  677. compact: exports.compact,
  678. separate: exports.separate
  679. };
  680. /**
  681. * @category instances
  682. * @since 2.7.0
  683. */
  684. exports.Filterable = {
  685. URI: exports.URI,
  686. map: _map,
  687. compact: exports.compact,
  688. separate: exports.separate,
  689. filter: _filter,
  690. filterMap: _filterMap,
  691. partition: _partition,
  692. partitionMap: _partitionMap
  693. };
  694. /**
  695. * @category folding
  696. * @since 2.11.0
  697. */
  698. var reduce = function (O) {
  699. var reduceWithIndexO = (0, exports.reduceWithIndex)(O);
  700. return function (b, f) { return reduceWithIndexO(b, function (_, b, a) { return f(b, a); }); };
  701. };
  702. exports.reduce = reduce;
  703. /**
  704. * @category folding
  705. * @since 2.11.0
  706. */
  707. var foldMap = function (O) {
  708. var foldMapWithIndexO = (0, exports.foldMapWithIndex)(O);
  709. return function (M) {
  710. var foldMapWithIndexOM = foldMapWithIndexO(M);
  711. return function (f) { return foldMapWithIndexOM(function (_, a) { return f(a); }); };
  712. };
  713. };
  714. exports.foldMap = foldMap;
  715. /**
  716. * @category folding
  717. * @since 2.11.0
  718. */
  719. var reduceRight = function (O) {
  720. var reduceRightWithIndexO = (0, exports.reduceRightWithIndex)(O);
  721. return function (b, f) { return reduceRightWithIndexO(b, function (_, b, a) { return f(b, a); }); };
  722. };
  723. exports.reduceRight = reduceRight;
  724. /**
  725. * @category folding
  726. * @since 2.10.0
  727. */
  728. var getFoldable = function (O) {
  729. var reduceO = (0, exports.reduce)(O);
  730. var foldMapO = (0, exports.foldMap)(O);
  731. var reduceRightO = (0, exports.reduceRight)(O);
  732. return {
  733. URI: exports.URI,
  734. _E: undefined,
  735. reduce: function (fa, b, f) { return (0, function_1.pipe)(fa, reduceO(b, f)); },
  736. foldMap: function (M) {
  737. var foldMapOM = foldMapO(M);
  738. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapOM(f)); };
  739. },
  740. reduceRight: function (fa, b, f) { return (0, function_1.pipe)(fa, reduceRightO(b, f)); }
  741. };
  742. };
  743. exports.getFoldable = getFoldable;
  744. /**
  745. * @category folding
  746. * @since 2.11.0
  747. */
  748. var reduceWithIndex = function (O) {
  749. var keysO = (0, exports.keys)(O);
  750. return function (b, f) { return function (m) {
  751. var out = b;
  752. for (var _i = 0, _a = keysO(m); _i < _a.length; _i++) {
  753. var k = _a[_i];
  754. out = f(k, out, m.get(k));
  755. }
  756. return out;
  757. }; };
  758. };
  759. exports.reduceWithIndex = reduceWithIndex;
  760. /**
  761. * @category folding
  762. * @since 2.11.0
  763. */
  764. var foldMapWithIndex = function (O) {
  765. var keysO = (0, exports.keys)(O);
  766. return function (M) { return function (f) { return function (m) {
  767. var out = M.empty;
  768. for (var _i = 0, _a = keysO(m); _i < _a.length; _i++) {
  769. var k = _a[_i];
  770. out = M.concat(out, f(k, m.get(k)));
  771. }
  772. return out;
  773. }; }; };
  774. };
  775. exports.foldMapWithIndex = foldMapWithIndex;
  776. /**
  777. * @category folding
  778. * @since 2.11.0
  779. */
  780. var reduceRightWithIndex = function (O) {
  781. var keysO = (0, exports.keys)(O);
  782. return function (b, f) { return function (m) {
  783. var out = b;
  784. var ks = keysO(m);
  785. var len = ks.length;
  786. for (var i = len - 1; i >= 0; i--) {
  787. var k = ks[i];
  788. out = f(k, m.get(k), out);
  789. }
  790. return out;
  791. }; };
  792. };
  793. exports.reduceRightWithIndex = reduceRightWithIndex;
  794. /**
  795. * @category folding
  796. * @since 2.10.0
  797. */
  798. var getFoldableWithIndex = function (O) {
  799. var F = (0, exports.getFoldable)(O);
  800. var reduceWithIndexO = (0, exports.reduceWithIndex)(O);
  801. var foldMapWithIndexO = (0, exports.foldMapWithIndex)(O);
  802. var reduceRightWithIndexO = (0, exports.reduceRightWithIndex)(O);
  803. return {
  804. URI: exports.URI,
  805. _E: undefined,
  806. reduce: F.reduce,
  807. foldMap: F.foldMap,
  808. reduceRight: F.reduceRight,
  809. reduceWithIndex: function (fa, b, f) { return (0, function_1.pipe)(fa, reduceWithIndexO(b, f)); },
  810. foldMapWithIndex: function (M) {
  811. var foldMapWithIndexOM = foldMapWithIndexO(M);
  812. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapWithIndexOM(f)); };
  813. },
  814. reduceRightWithIndex: function (fa, b, f) { return (0, function_1.pipe)(fa, reduceRightWithIndexO(b, f)); }
  815. };
  816. };
  817. exports.getFoldableWithIndex = getFoldableWithIndex;
  818. /**
  819. * @category traversing
  820. * @since 2.10.0
  821. */
  822. var getTraversable = function (O) {
  823. var TWI = (0, exports.getTraversableWithIndex)(O);
  824. var F = (0, exports.getFoldable)(O);
  825. return {
  826. URI: exports.URI,
  827. _E: undefined,
  828. map: _map,
  829. reduce: F.reduce,
  830. foldMap: F.foldMap,
  831. reduceRight: F.reduceRight,
  832. traverse: TWI.traverse,
  833. sequence: TWI.sequence
  834. };
  835. };
  836. exports.getTraversable = getTraversable;
  837. /**
  838. * @category traversing
  839. * @since 2.10.0
  840. */
  841. var getTraversableWithIndex = function (O) {
  842. var FWI = (0, exports.getFoldableWithIndex)(O);
  843. var keysO = (0, exports.keys)(O);
  844. var traverseWithIndex = function (F) {
  845. return function (ta, f) {
  846. var fm = F.of(new Map());
  847. var ks = keysO(ta);
  848. var len = ks.length;
  849. var _loop_1 = function (i) {
  850. var key = ks[i];
  851. var a = ta.get(key);
  852. fm = F.ap(F.map(fm, function (m) { return function (b) { return m.set(key, b); }; }), f(key, a));
  853. };
  854. for (var i = 0; i < len; i++) {
  855. _loop_1(i);
  856. }
  857. return fm;
  858. };
  859. };
  860. var traverse = function (F) {
  861. var traverseWithIndexF = traverseWithIndex(F);
  862. return function (ta, f) { return traverseWithIndexF(ta, function (_, a) { return f(a); }); };
  863. };
  864. var sequence = function (F) {
  865. var traverseWithIndexF = traverseWithIndex(F);
  866. return function (ta) { return traverseWithIndexF(ta, function_1.SK); };
  867. };
  868. return {
  869. URI: exports.URI,
  870. _E: undefined,
  871. map: _map,
  872. mapWithIndex: _mapWithIndex,
  873. reduce: FWI.reduce,
  874. foldMap: FWI.foldMap,
  875. reduceRight: FWI.reduceRight,
  876. reduceWithIndex: FWI.reduceWithIndex,
  877. foldMapWithIndex: FWI.foldMapWithIndex,
  878. reduceRightWithIndex: FWI.reduceRightWithIndex,
  879. traverse: traverse,
  880. sequence: sequence,
  881. traverseWithIndex: traverseWithIndex
  882. };
  883. };
  884. exports.getTraversableWithIndex = getTraversableWithIndex;
  885. /**
  886. * @category filtering
  887. * @since 2.5.0
  888. */
  889. function getWitherable(O) {
  890. var TWI = (0, exports.getTraversableWithIndex)(O);
  891. return {
  892. URI: exports.URI,
  893. _E: undefined,
  894. map: _map,
  895. compact: exports.compact,
  896. separate: exports.separate,
  897. filter: _filter,
  898. filterMap: _filterMap,
  899. partition: _partition,
  900. partitionMap: _partitionMap,
  901. reduce: TWI.reduce,
  902. foldMap: TWI.foldMap,
  903. reduceRight: TWI.reduceRight,
  904. traverse: TWI.traverse,
  905. sequence: TWI.sequence,
  906. mapWithIndex: _mapWithIndex,
  907. reduceWithIndex: TWI.reduceWithIndex,
  908. foldMapWithIndex: TWI.foldMapWithIndex,
  909. reduceRightWithIndex: TWI.reduceRightWithIndex,
  910. traverseWithIndex: TWI.traverseWithIndex,
  911. wilt: (0, Witherable_1.wiltDefault)(TWI, exports.Compactable),
  912. wither: (0, Witherable_1.witherDefault)(TWI, exports.Compactable)
  913. };
  914. }
  915. exports.getWitherable = getWitherable;
  916. // -------------------------------------------------------------------------------------
  917. // utils
  918. // -------------------------------------------------------------------------------------
  919. /**
  920. * @since 2.11.0
  921. */
  922. var union = function (E, M) {
  923. var lookupE = lookup(E);
  924. return function (second) { return function (first) {
  925. if ((0, exports.isEmpty)(first)) {
  926. return second;
  927. }
  928. if ((0, exports.isEmpty)(second)) {
  929. return first;
  930. }
  931. var out = new Map();
  932. var firstEntries = first.entries();
  933. var e;
  934. while (!(e = firstEntries.next()).done) {
  935. var _a = e.value, k = _a[0], a = _a[1];
  936. var oka = lookupE(k)(second);
  937. if (_.isSome(oka)) {
  938. out.set(k, M.concat(a, oka.value));
  939. }
  940. else {
  941. out.set(k, a);
  942. }
  943. }
  944. var secondEntries = second.entries();
  945. while (!(e = secondEntries.next()).done) {
  946. var _b = e.value, k = _b[0], a = _b[1];
  947. var oka = lookupE(k)(out);
  948. if (_.isNone(oka)) {
  949. out.set(k, a);
  950. }
  951. }
  952. return out;
  953. }; };
  954. };
  955. exports.union = union;
  956. /**
  957. * @since 2.11.0
  958. */
  959. var intersection = function (E, M) {
  960. var lookupE = lookup(E);
  961. return function (second) { return function (first) {
  962. if ((0, exports.isEmpty)(first) || (0, exports.isEmpty)(second)) {
  963. return exports.empty;
  964. }
  965. var out = new Map();
  966. var entries = first.entries();
  967. var e;
  968. while (!(e = entries.next()).done) {
  969. var _a = e.value, k = _a[0], a = _a[1];
  970. var oka = lookupE(k)(second);
  971. if (_.isSome(oka)) {
  972. out.set(k, M.concat(a, oka.value));
  973. }
  974. }
  975. return out;
  976. }; };
  977. };
  978. exports.intersection = intersection;
  979. /**
  980. * @since 2.11.0
  981. */
  982. var difference = function (E) {
  983. var memberE = member(E);
  984. return function (second) {
  985. return function (first) {
  986. if ((0, exports.isEmpty)(first)) {
  987. return second;
  988. }
  989. if ((0, exports.isEmpty)(second)) {
  990. return first;
  991. }
  992. var out = new Map();
  993. var firstEntries = first.entries();
  994. var e;
  995. while (!(e = firstEntries.next()).done) {
  996. var _a = e.value, k = _a[0], a = _a[1];
  997. if (!memberE(k)(second)) {
  998. out.set(k, a);
  999. }
  1000. }
  1001. var secondEntries = second.entries();
  1002. while (!(e = secondEntries.next()).done) {
  1003. var _b = e.value, k = _b[0], a = _b[1];
  1004. if (!memberE(k)(first)) {
  1005. out.set(k, a);
  1006. }
  1007. }
  1008. return out;
  1009. };
  1010. };
  1011. };
  1012. exports.difference = difference;
  1013. // -------------------------------------------------------------------------------------
  1014. // deprecated
  1015. // -------------------------------------------------------------------------------------
  1016. /**
  1017. * Use [`upsertAt`](#upsertat) instead.
  1018. *
  1019. @category zone of death
  1020. * @since 2.5.0
  1021. * @deprecated
  1022. */
  1023. exports.insertAt = exports.upsertAt;
  1024. /**
  1025. * This instance is deprecated, use small, specific instances instead.
  1026. * For example if a function needs a `Functor` instance, pass `RM.Functor` instead of `RM.readonlyMap`
  1027. * (where `RM` is from `import RM from 'fp-ts/ReadonlyMap'`)
  1028. *
  1029. * @category zone of death
  1030. * @since 2.5.0
  1031. * @deprecated
  1032. */
  1033. exports.readonlyMap = {
  1034. URI: exports.URI,
  1035. map: _map,
  1036. compact: exports.compact,
  1037. separate: exports.separate,
  1038. filter: _filter,
  1039. filterMap: _filterMap,
  1040. partition: _partition,
  1041. partitionMap: _partitionMap
  1042. };