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

726 строки
22 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.toTuple = exports.toTuple2 = exports.exists = exports.elem = exports.fromOptionK = exports.fromOption = exports.fromPredicate = exports.FromEither = exports.Traversable = exports.Foldable = exports.FromThese = exports.Bifunctor = exports.Pointed = exports.flap = exports.Functor = exports.URI = exports.of = exports.sequence = exports.traverse = exports.reduceRight = exports.foldMap = exports.reduce = exports.map = exports.mapLeft = exports.bimap = exports.fromOptions = exports.getRightOnly = exports.getLeftOnly = exports.rightOrBoth = exports.leftOrBoth = exports.getRight = exports.getLeft = exports.getMonad = exports.getChain = exports.getApplicative = exports.getApply = exports.getSemigroup = exports.getEq = exports.getShow = exports.swap = exports.fold = exports.match = exports.foldW = exports.matchW = exports.both = exports.right = exports.left = exports.isBoth = exports.isRight = exports.isLeft = void 0;
  27. exports.these = exports.traverseReadonlyArrayWithIndex = exports.traverseReadonlyNonEmptyArrayWithIndex = exports.ApT = void 0;
  28. var Eq_1 = require("./Eq");
  29. var FromEither_1 = require("./FromEither");
  30. var function_1 = require("./function");
  31. var Functor_1 = require("./Functor");
  32. var _ = __importStar(require("./internal"));
  33. // -------------------------------------------------------------------------------------
  34. // refinements
  35. // -------------------------------------------------------------------------------------
  36. /**
  37. * Returns `true` if the these is an instance of `Left`, `false` otherwise
  38. *
  39. * @category refinements
  40. * @since 2.0.0
  41. */
  42. var isLeft = function (fa) { return fa._tag === 'Left'; };
  43. exports.isLeft = isLeft;
  44. /**
  45. * Returns `true` if the these is an instance of `Right`, `false` otherwise
  46. *
  47. * @category refinements
  48. * @since 2.0.0
  49. */
  50. var isRight = function (fa) { return fa._tag === 'Right'; };
  51. exports.isRight = isRight;
  52. /**
  53. * Returns `true` if the these is an instance of `Both`, `false` otherwise
  54. *
  55. * @category refinements
  56. * @since 2.0.0
  57. */
  58. function isBoth(fa) {
  59. return fa._tag === 'Both';
  60. }
  61. exports.isBoth = isBoth;
  62. // -------------------------------------------------------------------------------------
  63. // constructors
  64. // -------------------------------------------------------------------------------------
  65. /**
  66. * @category constructors
  67. * @since 2.0.0
  68. */
  69. function left(left) {
  70. return { _tag: 'Left', left: left };
  71. }
  72. exports.left = left;
  73. /**
  74. * @category constructors
  75. * @since 2.0.0
  76. */
  77. function right(right) {
  78. return { _tag: 'Right', right: right };
  79. }
  80. exports.right = right;
  81. /**
  82. * @category constructors
  83. * @since 2.0.0
  84. */
  85. function both(left, right) {
  86. return { _tag: 'Both', left: left, right: right };
  87. }
  88. exports.both = both;
  89. /**
  90. * Less strict version of [`match`](#match).
  91. *
  92. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  93. *
  94. * @category pattern matching
  95. * @since 2.10.0
  96. */
  97. var matchW = function (onLeft, onRight, onBoth) {
  98. return function (fa) {
  99. switch (fa._tag) {
  100. case 'Left':
  101. return onLeft(fa.left);
  102. case 'Right':
  103. return onRight(fa.right);
  104. case 'Both':
  105. return onBoth(fa.left, fa.right);
  106. }
  107. };
  108. };
  109. exports.matchW = matchW;
  110. /**
  111. * Alias of [`matchW`](#matchw).
  112. *
  113. * @category pattern matching
  114. * @since 2.10.0
  115. */
  116. exports.foldW = exports.matchW;
  117. /**
  118. * @category pattern matching
  119. * @since 2.10.0
  120. */
  121. exports.match = exports.matchW;
  122. /**
  123. * Alias of [`match`](#match).
  124. *
  125. * @category pattern matching
  126. * @since 2.0.0
  127. */
  128. exports.fold = exports.match;
  129. /**
  130. * @since 2.4.0
  131. */
  132. exports.swap = (0, exports.match)(right, left, function (e, a) { return both(a, e); });
  133. /**
  134. * @category instances
  135. * @since 2.0.0
  136. */
  137. function getShow(SE, SA) {
  138. return {
  139. show: (0, exports.match)(function (l) { return "left(".concat(SE.show(l), ")"); }, function (a) { return "right(".concat(SA.show(a), ")"); }, function (l, a) { return "both(".concat(SE.show(l), ", ").concat(SA.show(a), ")"); })
  140. };
  141. }
  142. exports.getShow = getShow;
  143. /**
  144. * @category instances
  145. * @since 2.0.0
  146. */
  147. function getEq(EE, EA) {
  148. return (0, Eq_1.fromEquals)(function (x, y) {
  149. return (0, exports.isLeft)(x)
  150. ? (0, exports.isLeft)(y) && EE.equals(x.left, y.left)
  151. : (0, exports.isRight)(x)
  152. ? (0, exports.isRight)(y) && EA.equals(x.right, y.right)
  153. : isBoth(y) && EE.equals(x.left, y.left) && EA.equals(x.right, y.right);
  154. });
  155. }
  156. exports.getEq = getEq;
  157. /**
  158. * @category instances
  159. * @since 2.0.0
  160. */
  161. function getSemigroup(SE, SA) {
  162. return {
  163. concat: function (x, y) {
  164. return (0, exports.isLeft)(x)
  165. ? (0, exports.isLeft)(y)
  166. ? left(SE.concat(x.left, y.left))
  167. : (0, exports.isRight)(y)
  168. ? both(x.left, y.right)
  169. : both(SE.concat(x.left, y.left), y.right)
  170. : (0, exports.isRight)(x)
  171. ? (0, exports.isLeft)(y)
  172. ? both(y.left, x.right)
  173. : (0, exports.isRight)(y)
  174. ? right(SA.concat(x.right, y.right))
  175. : both(y.left, SA.concat(x.right, y.right))
  176. : (0, exports.isLeft)(y)
  177. ? both(SE.concat(x.left, y.left), x.right)
  178. : (0, exports.isRight)(y)
  179. ? both(x.left, SA.concat(x.right, y.right))
  180. : both(SE.concat(x.left, y.left), SA.concat(x.right, y.right));
  181. }
  182. };
  183. }
  184. exports.getSemigroup = getSemigroup;
  185. /**
  186. * @category instances
  187. * @since 2.10.0
  188. */
  189. var getApply = function (S) { return ({
  190. URI: exports.URI,
  191. _E: undefined,
  192. map: _map,
  193. ap: function (fab, fa) {
  194. return (0, exports.isLeft)(fab)
  195. ? (0, exports.isLeft)(fa)
  196. ? left(S.concat(fab.left, fa.left))
  197. : (0, exports.isRight)(fa)
  198. ? left(fab.left)
  199. : left(S.concat(fab.left, fa.left))
  200. : (0, exports.isRight)(fab)
  201. ? (0, exports.isLeft)(fa)
  202. ? left(fa.left)
  203. : (0, exports.isRight)(fa)
  204. ? right(fab.right(fa.right))
  205. : both(fa.left, fab.right(fa.right))
  206. : (0, exports.isLeft)(fa)
  207. ? left(S.concat(fab.left, fa.left))
  208. : (0, exports.isRight)(fa)
  209. ? both(fab.left, fab.right(fa.right))
  210. : both(S.concat(fab.left, fa.left), fab.right(fa.right));
  211. }
  212. }); };
  213. exports.getApply = getApply;
  214. /**
  215. * @category instances
  216. * @since 2.7.0
  217. */
  218. function getApplicative(S) {
  219. var A = (0, exports.getApply)(S);
  220. return {
  221. URI: exports.URI,
  222. _E: undefined,
  223. map: _map,
  224. ap: A.ap,
  225. of: exports.of
  226. };
  227. }
  228. exports.getApplicative = getApplicative;
  229. /**
  230. * @category instances
  231. * @since 2.10.0
  232. */
  233. function getChain(S) {
  234. var A = (0, exports.getApply)(S);
  235. var chain = function (ma, f) {
  236. if ((0, exports.isLeft)(ma)) {
  237. return ma;
  238. }
  239. if ((0, exports.isRight)(ma)) {
  240. return f(ma.right);
  241. }
  242. var fb = f(ma.right);
  243. return (0, exports.isLeft)(fb)
  244. ? left(S.concat(ma.left, fb.left))
  245. : (0, exports.isRight)(fb)
  246. ? both(ma.left, fb.right)
  247. : both(S.concat(ma.left, fb.left), fb.right);
  248. };
  249. return {
  250. URI: exports.URI,
  251. _E: undefined,
  252. map: _map,
  253. ap: A.ap,
  254. chain: chain
  255. };
  256. }
  257. exports.getChain = getChain;
  258. /**
  259. * @category instances
  260. * @since 2.0.0
  261. */
  262. function getMonad(S) {
  263. var C = getChain(S);
  264. return {
  265. URI: exports.URI,
  266. _E: undefined,
  267. map: _map,
  268. of: exports.of,
  269. ap: C.ap,
  270. chain: C.chain,
  271. throwError: left
  272. };
  273. }
  274. exports.getMonad = getMonad;
  275. /**
  276. * Returns an `E` value if possible
  277. *
  278. * @example
  279. * import { getLeft, left, right, both } from 'fp-ts/These'
  280. * import { none, some } from 'fp-ts/Option'
  281. *
  282. * assert.deepStrictEqual(getLeft(left('a')), some('a'))
  283. * assert.deepStrictEqual(getLeft(right(1)), none)
  284. * assert.deepStrictEqual(getLeft(both('a', 1)), some('a'))
  285. *
  286. * @category conversions
  287. * @since 2.0.0
  288. */
  289. function getLeft(fa) {
  290. return (0, exports.isLeft)(fa) ? _.some(fa.left) : (0, exports.isRight)(fa) ? _.none : _.some(fa.left);
  291. }
  292. exports.getLeft = getLeft;
  293. /**
  294. * Returns an `A` value if possible
  295. *
  296. * @example
  297. * import { getRight, left, right, both } from 'fp-ts/These'
  298. * import { none, some } from 'fp-ts/Option'
  299. *
  300. * assert.deepStrictEqual(getRight(left('a')), none)
  301. * assert.deepStrictEqual(getRight(right(1)), some(1))
  302. * assert.deepStrictEqual(getRight(both('a', 1)), some(1))
  303. *
  304. * @category conversions
  305. * @since 2.0.0
  306. */
  307. function getRight(fa) {
  308. return (0, exports.isLeft)(fa) ? _.none : (0, exports.isRight)(fa) ? _.some(fa.right) : _.some(fa.right);
  309. }
  310. exports.getRight = getRight;
  311. // TODO: make lazy in v3
  312. /**
  313. * @example
  314. * import { leftOrBoth, left, both } from 'fp-ts/These'
  315. * import { none, some } from 'fp-ts/Option'
  316. *
  317. * assert.deepStrictEqual(leftOrBoth('a')(none), left('a'))
  318. * assert.deepStrictEqual(leftOrBoth('a')(some(1)), both('a', 1))
  319. *
  320. * @category constructors
  321. * @since 2.0.0
  322. */
  323. function leftOrBoth(e) {
  324. return function (ma) { return (_.isNone(ma) ? left(e) : both(e, ma.value)); };
  325. }
  326. exports.leftOrBoth = leftOrBoth;
  327. // TODO: make lazy in v3
  328. /**
  329. * @example
  330. * import { rightOrBoth, right, both } from 'fp-ts/These'
  331. * import { none, some } from 'fp-ts/Option'
  332. *
  333. * assert.deepStrictEqual(rightOrBoth(1)(none), right(1))
  334. * assert.deepStrictEqual(rightOrBoth(1)(some('a')), both('a', 1))
  335. *
  336. * @category constructors
  337. * @since 2.0.0
  338. */
  339. function rightOrBoth(a) {
  340. return function (me) { return (_.isNone(me) ? right(a) : both(me.value, a)); };
  341. }
  342. exports.rightOrBoth = rightOrBoth;
  343. /**
  344. * Returns the `E` value if and only if the value is constructed with `Left`
  345. *
  346. * @example
  347. * import { getLeftOnly, left, right, both } from 'fp-ts/These'
  348. * import { none, some } from 'fp-ts/Option'
  349. *
  350. * assert.deepStrictEqual(getLeftOnly(left('a')), some('a'))
  351. * assert.deepStrictEqual(getLeftOnly(right(1)), none)
  352. * assert.deepStrictEqual(getLeftOnly(both('a', 1)), none)
  353. *
  354. * @category conversions
  355. * @since 2.0.0
  356. */
  357. function getLeftOnly(fa) {
  358. return (0, exports.isLeft)(fa) ? _.some(fa.left) : _.none;
  359. }
  360. exports.getLeftOnly = getLeftOnly;
  361. /**
  362. * Returns the `A` value if and only if the value is constructed with `Right`
  363. *
  364. * @example
  365. * import { getRightOnly, left, right, both } from 'fp-ts/These'
  366. * import { none, some } from 'fp-ts/Option'
  367. *
  368. * assert.deepStrictEqual(getRightOnly(left('a')), none)
  369. * assert.deepStrictEqual(getRightOnly(right(1)), some(1))
  370. * assert.deepStrictEqual(getRightOnly(both('a', 1)), none)
  371. *
  372. * @category conversions
  373. * @since 2.0.0
  374. */
  375. function getRightOnly(fa) {
  376. return (0, exports.isRight)(fa) ? _.some(fa.right) : _.none;
  377. }
  378. exports.getRightOnly = getRightOnly;
  379. /**
  380. * Takes a pair of `Option`s and attempts to create a `These` from them
  381. *
  382. * @example
  383. * import { fromOptions, left, right, both } from 'fp-ts/These'
  384. * import { none, some } from 'fp-ts/Option'
  385. *
  386. * assert.deepStrictEqual(fromOptions(none, none), none)
  387. * assert.deepStrictEqual(fromOptions(some('a'), none), some(left('a')))
  388. * assert.deepStrictEqual(fromOptions(none, some(1)), some(right(1)))
  389. * assert.deepStrictEqual(fromOptions(some('a'), some(1)), some(both('a', 1)))
  390. *
  391. * @category conversions
  392. * @since 2.0.0
  393. */
  394. var fromOptions = function (fe, fa) {
  395. return _.isNone(fe)
  396. ? _.isNone(fa)
  397. ? _.none
  398. : _.some(right(fa.value))
  399. : _.isNone(fa)
  400. ? _.some(left(fe.value))
  401. : _.some(both(fe.value, fa.value));
  402. };
  403. exports.fromOptions = fromOptions;
  404. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  405. /* istanbul ignore next */
  406. var _bimap = function (fa, f, g) { return (0, function_1.pipe)(fa, (0, exports.bimap)(f, g)); };
  407. /* istanbul ignore next */
  408. var _mapLeft = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapLeft)(f)); };
  409. /* istanbul ignore next */
  410. var _reduce = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduce)(b, f)); };
  411. /* istanbul ignore next */
  412. var _foldMap = function (M) {
  413. var foldMapM = (0, exports.foldMap)(M);
  414. return function (fa, f) { return (0, function_1.pipe)(fa, foldMapM(f)); };
  415. };
  416. /* istanbul ignore next */
  417. var _reduceRight = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduceRight)(b, f)); };
  418. /* istanbul ignore next */
  419. var _traverse = function (F) {
  420. var traverseF = (0, exports.traverse)(F);
  421. return function (ta, f) { return (0, function_1.pipe)(ta, traverseF(f)); };
  422. };
  423. /**
  424. * Map a pair of functions over the two type arguments of the bifunctor.
  425. *
  426. * @category mapping
  427. * @since 2.0.0
  428. */
  429. var bimap = function (f, g) { return function (fa) {
  430. return (0, exports.isLeft)(fa) ? left(f(fa.left)) : (0, exports.isRight)(fa) ? right(g(fa.right)) : both(f(fa.left), g(fa.right));
  431. }; };
  432. exports.bimap = bimap;
  433. /**
  434. * Map a function over the first type argument of a bifunctor.
  435. *
  436. * @category error handling
  437. * @since 2.0.0
  438. */
  439. var mapLeft = function (f) { return function (fa) {
  440. return (0, exports.isLeft)(fa) ? left(f(fa.left)) : isBoth(fa) ? both(f(fa.left), fa.right) : fa;
  441. }; };
  442. exports.mapLeft = mapLeft;
  443. /**
  444. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  445. * use the type constructor `F` to represent some computational context.
  446. *
  447. * @category mapping
  448. * @since 2.0.0
  449. */
  450. var map = function (f) { return function (fa) {
  451. return (0, exports.isLeft)(fa) ? fa : (0, exports.isRight)(fa) ? right(f(fa.right)) : both(fa.left, f(fa.right));
  452. }; };
  453. exports.map = map;
  454. /**
  455. * @category folding
  456. * @since 2.0.0
  457. */
  458. var reduce = function (b, f) { return function (fa) {
  459. return (0, exports.isLeft)(fa) ? b : f(b, fa.right);
  460. }; };
  461. exports.reduce = reduce;
  462. /**
  463. * @category folding
  464. * @since 2.0.0
  465. */
  466. var foldMap = function (M) { return function (f) { return function (fa) {
  467. return (0, exports.isLeft)(fa) ? M.empty : f(fa.right);
  468. }; }; };
  469. exports.foldMap = foldMap;
  470. /**
  471. * @category folding
  472. * @since 2.0.0
  473. */
  474. var reduceRight = function (b, f) { return function (fa) {
  475. return (0, exports.isLeft)(fa) ? b : f(fa.right, b);
  476. }; };
  477. exports.reduceRight = reduceRight;
  478. /**
  479. * @category traversing
  480. * @since 2.6.3
  481. */
  482. var traverse = function (F) {
  483. return function (f) {
  484. return function (ta) {
  485. return (0, exports.isLeft)(ta) ? F.of(ta) : (0, exports.isRight)(ta) ? F.map(f(ta.right), right) : F.map(f(ta.right), function (b) { return both(ta.left, b); });
  486. };
  487. };
  488. };
  489. exports.traverse = traverse;
  490. /**
  491. * @category traversing
  492. * @since 2.6.3
  493. */
  494. var sequence = function (F) {
  495. return function (ta) {
  496. return (0, exports.isLeft)(ta) ? F.of(ta) : (0, exports.isRight)(ta) ? F.map(ta.right, right) : F.map(ta.right, function (b) { return both(ta.left, b); });
  497. };
  498. };
  499. exports.sequence = sequence;
  500. /**
  501. * @category constructors
  502. * @since 2.0.0
  503. */
  504. exports.of = right;
  505. /**
  506. * @category type lambdas
  507. * @since 2.0.0
  508. */
  509. exports.URI = 'These';
  510. /**
  511. * @category instances
  512. * @since 2.7.0
  513. */
  514. exports.Functor = {
  515. URI: exports.URI,
  516. map: _map
  517. };
  518. /**
  519. * @category mapping
  520. * @since 2.10.0
  521. */
  522. exports.flap = (0, Functor_1.flap)(exports.Functor);
  523. /**
  524. * @category instances
  525. * @since 2.10.0
  526. */
  527. exports.Pointed = {
  528. URI: exports.URI,
  529. of: exports.of
  530. };
  531. /**
  532. * @category instances
  533. * @since 2.7.0
  534. */
  535. exports.Bifunctor = {
  536. URI: exports.URI,
  537. bimap: _bimap,
  538. mapLeft: _mapLeft
  539. };
  540. /**
  541. * @category instances
  542. * @since 2.11.0
  543. */
  544. exports.FromThese = {
  545. URI: exports.URI,
  546. fromThese: function_1.identity
  547. };
  548. /**
  549. * @category instances
  550. * @since 2.7.0
  551. */
  552. exports.Foldable = {
  553. URI: exports.URI,
  554. reduce: _reduce,
  555. foldMap: _foldMap,
  556. reduceRight: _reduceRight
  557. };
  558. /**
  559. * @category instances
  560. * @since 2.7.0
  561. */
  562. exports.Traversable = {
  563. URI: exports.URI,
  564. map: _map,
  565. reduce: _reduce,
  566. foldMap: _foldMap,
  567. reduceRight: _reduceRight,
  568. traverse: _traverse,
  569. sequence: exports.sequence
  570. };
  571. /**
  572. * @category instances
  573. * @since 2.10.0
  574. */
  575. exports.FromEither = {
  576. URI: exports.URI,
  577. fromEither: function_1.identity
  578. };
  579. /**
  580. * @category lifting
  581. * @since 2.13.0
  582. */
  583. exports.fromPredicate = (0, FromEither_1.fromPredicate)(exports.FromEither);
  584. /**
  585. * @category conversions
  586. * @since 2.10.0
  587. */
  588. exports.fromOption =
  589. /*#__PURE__*/ (0, FromEither_1.fromOption)(exports.FromEither);
  590. /**
  591. * @category lifting
  592. * @since 2.10.0
  593. */
  594. exports.fromOptionK =
  595. /*#__PURE__*/ (0, FromEither_1.fromOptionK)(exports.FromEither);
  596. // -------------------------------------------------------------------------------------
  597. // utils
  598. // -------------------------------------------------------------------------------------
  599. /**
  600. * @since 2.11.0
  601. */
  602. var elem = function (E) {
  603. return function (a) {
  604. return function (ma) {
  605. return (0, exports.isLeft)(ma) ? false : E.equals(a, ma.right);
  606. };
  607. };
  608. };
  609. exports.elem = elem;
  610. /**
  611. * @since 2.11.0
  612. */
  613. var exists = function (predicate) {
  614. return function (ma) {
  615. return (0, exports.isLeft)(ma) ? false : predicate(ma.right);
  616. };
  617. };
  618. exports.exists = exists;
  619. /**
  620. * @example
  621. * import { toTuple2, left, right, both } from 'fp-ts/These'
  622. *
  623. * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(left('b')), ['b', 1])
  624. * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(right(2)), ['a', 2])
  625. * assert.deepStrictEqual(toTuple2(() => 'a', () => 1)(both('b', 2)), ['b', 2])
  626. *
  627. * @category conversions
  628. * @since 2.10.0
  629. */
  630. var toTuple2 = function (e, a) {
  631. return function (fa) {
  632. return (0, exports.isLeft)(fa) ? [fa.left, a()] : (0, exports.isRight)(fa) ? [e(), fa.right] : [fa.left, fa.right];
  633. };
  634. };
  635. exports.toTuple2 = toTuple2;
  636. // -------------------------------------------------------------------------------------
  637. // deprecated
  638. // -------------------------------------------------------------------------------------
  639. /**
  640. * Use [`toTuple2`](#totuple2) instead.
  641. *
  642. * @category zone of death
  643. * @since 2.0.0
  644. * @deprecated
  645. */
  646. var toTuple = function (e, a) {
  647. return (0, exports.toTuple2)(function () { return e; }, function () { return a; });
  648. };
  649. exports.toTuple = toTuple;
  650. /**
  651. * @since 2.11.0
  652. */
  653. exports.ApT = (0, exports.of)(_.emptyReadonlyArray);
  654. // -------------------------------------------------------------------------------------
  655. // array utils
  656. // -------------------------------------------------------------------------------------
  657. /**
  658. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(getApplicative(S))`.
  659. *
  660. * @category traversing
  661. * @since 2.11.0
  662. */
  663. var traverseReadonlyNonEmptyArrayWithIndex = function (S) {
  664. return function (f) {
  665. return function (as) {
  666. var e = _.none;
  667. var t = f(0, _.head(as));
  668. if ((0, exports.isLeft)(t)) {
  669. return t;
  670. }
  671. if (isBoth(t)) {
  672. e = _.some(t.left);
  673. }
  674. var out = [t.right];
  675. for (var i = 1; i < as.length; i++) {
  676. var t_1 = f(i, as[i]);
  677. if ((0, exports.isLeft)(t_1)) {
  678. return t_1;
  679. }
  680. if (isBoth(t_1)) {
  681. e = _.isNone(e) ? _.some(t_1.left) : _.some(S.concat(e.value, t_1.left));
  682. }
  683. out.push(t_1.right);
  684. }
  685. return _.isNone(e) ? right(out) : both(e.value, out);
  686. };
  687. };
  688. };
  689. exports.traverseReadonlyNonEmptyArrayWithIndex = traverseReadonlyNonEmptyArrayWithIndex;
  690. /**
  691. * Equivalent to `ReadonlyArray#traverseWithIndex(getApplicative(S))`.
  692. *
  693. * @category traversing
  694. * @since 2.11.0
  695. */
  696. var traverseReadonlyArrayWithIndex = function (S) {
  697. return function (f) {
  698. var g = (0, exports.traverseReadonlyNonEmptyArrayWithIndex)(S)(f);
  699. return function (as) { return (_.isNonEmpty(as) ? g(as) : exports.ApT); };
  700. };
  701. };
  702. exports.traverseReadonlyArrayWithIndex = traverseReadonlyArrayWithIndex;
  703. // -------------------------------------------------------------------------------------
  704. // deprecated
  705. // -------------------------------------------------------------------------------------
  706. /**
  707. * This instance is deprecated, use small, specific instances instead.
  708. * For example if a function needs a `Functor` instance, pass `T.Functor` instead of `T.these`
  709. * (where `T` is from `import T from 'fp-ts/These'`)
  710. *
  711. * @category zone of death
  712. * @since 2.0.0
  713. * @deprecated
  714. */
  715. exports.these = {
  716. URI: exports.URI,
  717. map: _map,
  718. bimap: _bimap,
  719. mapLeft: _mapLeft,
  720. reduce: _reduce,
  721. foldMap: _foldMap,
  722. reduceRight: _reduceRight,
  723. traverse: _traverse,
  724. sequence: exports.sequence
  725. };