版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

825 line
24 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.apSecondW = exports.apSecond = exports.apFirstW = exports.apFirst = exports.Apply = exports.Pointed = exports.flap = exports.Functor = exports.getAltReaderValidation = exports.getApplicativeReaderValidation = exports.getFilterable = exports.getCompactable = exports.URI = exports.throwError = exports.altW = exports.alt = exports.flatten = exports.flattenW = exports.chainW = exports.chain = exports.of = exports.apW = exports.ap = exports.mapLeft = exports.bimap = exports.map = exports.swap = exports.orLeft = exports.orElseFirstW = exports.orElseFirst = exports.orElseW = exports.orElse = exports.asksReaderEither = exports.asksReaderEitherW = exports.local = exports.toUnion = exports.getOrElseW = exports.getOrElse = exports.foldW = exports.matchEW = exports.fold = exports.matchE = exports.matchW = exports.match = exports.fromReader = exports.fromEither = exports.leftReader = exports.rightReader = exports.right = exports.left = void 0;
  27. exports.getReaderValidation = exports.getSemigroup = exports.getApplyMonoid = exports.getApplySemigroup = exports.readerEither = exports.sequenceArray = exports.traverseArray = exports.traverseArrayWithIndex = exports.traverseReadonlyArrayWithIndex = exports.traverseReadonlyNonEmptyArrayWithIndex = exports.ApT = exports.apSW = exports.apS = exports.bindW = exports.bind = exports.let = exports.bindTo = exports.Do = exports.fromEitherK = exports.filterOrElseW = exports.filterOrElse = exports.fromPredicate = exports.chainFirstEitherKW = exports.chainFirstEitherK = exports.chainEitherKW = exports.chainEitherK = exports.chainOptionK = exports.fromOptionK = exports.fromOption = exports.FromEither = exports.MonadThrow = exports.chainFirstReaderKW = exports.chainFirstReaderK = exports.chainReaderKW = exports.chainReaderK = exports.fromReaderK = exports.asks = exports.ask = exports.FromReader = exports.Alt = exports.Bifunctor = exports.chainFirstW = exports.chainFirst = exports.Monad = exports.Chain = exports.Applicative = void 0;
  28. var Applicative_1 = require("./Applicative");
  29. var Apply_1 = require("./Apply");
  30. var Chain_1 = require("./Chain");
  31. var Compactable_1 = require("./Compactable");
  32. var E = __importStar(require("./Either"));
  33. var ET = __importStar(require("./EitherT"));
  34. var Filterable_1 = require("./Filterable");
  35. var FromEither_1 = require("./FromEither");
  36. var FromReader_1 = require("./FromReader");
  37. var function_1 = require("./function");
  38. var Functor_1 = require("./Functor");
  39. var _ = __importStar(require("./internal"));
  40. var R = __importStar(require("./Reader"));
  41. // -------------------------------------------------------------------------------------
  42. // constructors
  43. // -------------------------------------------------------------------------------------
  44. /**
  45. * @category constructors
  46. * @since 2.0.0
  47. */
  48. exports.left = ET.left(R.Pointed);
  49. /**
  50. * @category constructors
  51. * @since 2.0.0
  52. */
  53. exports.right = ET.right(R.Pointed);
  54. /**
  55. * @category constructors
  56. * @since 2.0.0
  57. */
  58. exports.rightReader =
  59. /*#__PURE__*/ ET.rightF(R.Functor);
  60. /**
  61. * @category constructors
  62. * @since 2.0.0
  63. */
  64. exports.leftReader = ET.leftF(R.Functor);
  65. // -------------------------------------------------------------------------------------
  66. // conversions
  67. // -------------------------------------------------------------------------------------
  68. /**
  69. * @category conversions
  70. * @since 2.0.0
  71. */
  72. exports.fromEither = R.of;
  73. /**
  74. * @category conversions
  75. * @since 2.11.0
  76. */
  77. exports.fromReader = exports.rightReader;
  78. /**
  79. * @category pattern matching
  80. * @since 2.10.0
  81. */
  82. exports.match = ET.match(R.Functor);
  83. /**
  84. * Less strict version of [`match`](#match).
  85. *
  86. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  87. *
  88. * @category pattern matching
  89. * @since 2.10.0
  90. */
  91. exports.matchW = exports.match;
  92. /**
  93. * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`Reader`).
  94. *
  95. * @category pattern matching
  96. * @since 2.10.0
  97. */
  98. exports.matchE = ET.matchE(R.Monad);
  99. /**
  100. * Alias of [`matchE`](#matche).
  101. *
  102. * @category pattern matching
  103. * @since 2.0.0
  104. */
  105. exports.fold = exports.matchE;
  106. /**
  107. * Less strict version of [`matchE`](#matche).
  108. *
  109. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  110. *
  111. * @category pattern matching
  112. * @since 2.10.0
  113. */
  114. exports.matchEW = exports.matchE;
  115. /**
  116. * Alias of [`matchEW`](#matchew).
  117. *
  118. * @category pattern matching
  119. * @since 2.10.0
  120. */
  121. exports.foldW = exports.matchEW;
  122. /**
  123. * @category error handling
  124. * @since 2.0.0
  125. */
  126. exports.getOrElse =
  127. /*#__PURE__*/ ET.getOrElse(R.Monad);
  128. /**
  129. * Less strict version of [`getOrElse`](#getorelse).
  130. *
  131. * The `W` suffix (short for **W**idening) means that the handler return type will be merged.
  132. *
  133. * @category error handling
  134. * @since 2.6.0
  135. */
  136. exports.getOrElseW = exports.getOrElse;
  137. /**
  138. * @category conversions
  139. * @since 2.10.0
  140. */
  141. exports.toUnion = ET.toUnion(R.Functor);
  142. // -------------------------------------------------------------------------------------
  143. // combinators
  144. // -------------------------------------------------------------------------------------
  145. /**
  146. * Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s
  147. * `contramap`).
  148. *
  149. * @since 2.0.0
  150. */
  151. exports.local = R.local;
  152. /**
  153. * Less strict version of [`asksReaderEither`](#asksreadereither).
  154. *
  155. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  156. *
  157. * @category constructors
  158. * @since 2.11.0
  159. */
  160. exports.asksReaderEitherW = R.asksReaderW;
  161. /**
  162. * Effectfully accesses the environment.
  163. *
  164. * @category constructors
  165. * @since 2.11.0
  166. */
  167. exports.asksReaderEither = exports.asksReaderEitherW;
  168. /**
  169. * @category error handling
  170. * @since 2.0.0
  171. */
  172. exports.orElse = ET.orElse(R.Monad);
  173. /**
  174. * Less strict version of [`orElse`](#orelse).
  175. *
  176. * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged.
  177. *
  178. * @category error handling
  179. * @since 2.10.0
  180. */
  181. exports.orElseW = exports.orElse;
  182. /**
  183. * @category error handling
  184. * @since 2.11.0
  185. */
  186. exports.orElseFirst = ET.orElseFirst(R.Monad);
  187. /**
  188. * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged.
  189. *
  190. * @category error handling
  191. * @since 2.11.0
  192. */
  193. exports.orElseFirstW = exports.orElseFirst;
  194. /**
  195. * @category error handling
  196. * @since 2.11.0
  197. */
  198. exports.orLeft = ET.orLeft(R.Monad);
  199. /**
  200. * @since 2.0.0
  201. */
  202. exports.swap = ET.swap(R.Functor);
  203. /* istanbul ignore next */
  204. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  205. /* istanbul ignore next */
  206. var _bimap = function (fa, f, g) { return (0, function_1.pipe)(fa, (0, exports.bimap)(f, g)); };
  207. /* istanbul ignore next */
  208. var _mapLeft = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapLeft)(f)); };
  209. /* istanbul ignore next */
  210. var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); };
  211. /* istanbul ignore next */
  212. var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); };
  213. /* istanbul ignore next */
  214. var _alt = function (fa, that) { return (0, function_1.pipe)(fa, (0, exports.alt)(that)); };
  215. /**
  216. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  217. * use the type constructor `F` to represent some computational context.
  218. *
  219. * @category mapping
  220. * @since 2.0.0
  221. */
  222. exports.map =
  223. /*#__PURE__*/ ET.map(R.Functor);
  224. /**
  225. * Map a pair of functions over the two last type arguments of the bifunctor.
  226. *
  227. * @category mapping
  228. * @since 2.0.0
  229. */
  230. exports.bimap = ET.bimap(R.Functor);
  231. /**
  232. * Map a function over the second type argument of a bifunctor.
  233. *
  234. * @category error handling
  235. * @since 2.0.0
  236. */
  237. exports.mapLeft =
  238. /*#__PURE__*/ ET.mapLeft(R.Functor);
  239. /**
  240. * @since 2.0.0
  241. */
  242. exports.ap = ET.ap(R.Apply);
  243. /**
  244. * Less strict version of [`ap`](#ap).
  245. *
  246. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  247. *
  248. * @since 2.8.0
  249. */
  250. exports.apW = exports.ap;
  251. /**
  252. * @category constructors
  253. * @since 2.8.5
  254. */
  255. exports.of = exports.right;
  256. /**
  257. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  258. *
  259. * @category sequencing
  260. * @since 2.0.0
  261. */
  262. exports.chain = ET.chain(R.Monad);
  263. /**
  264. * Less strict version of [`chain`](#chain).
  265. *
  266. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  267. *
  268. * @category sequencing
  269. * @since 2.6.0
  270. */
  271. exports.chainW = exports.chain;
  272. /**
  273. * Less strict version of [`flatten`](#flatten).
  274. *
  275. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  276. *
  277. * @category sequencing
  278. * @since 2.11.0
  279. */
  280. exports.flattenW = (0, exports.chainW)(function_1.identity);
  281. /**
  282. * @category sequencing
  283. * @since 2.0.0
  284. */
  285. exports.flatten = exports.flattenW;
  286. /**
  287. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  288. * types of kind `* -> *`.
  289. *
  290. * @category error handling
  291. * @since 2.0.0
  292. */
  293. exports.alt =
  294. /*#__PURE__*/ ET.alt(R.Monad);
  295. /**
  296. * Less strict version of [`alt`](#alt).
  297. *
  298. * The `W` suffix (short for **W**idening) means that the environment, the error and the return types will be merged.
  299. *
  300. * @category error handling
  301. * @since 2.9.0
  302. */
  303. exports.altW = exports.alt;
  304. /**
  305. * @since 2.7.0
  306. */
  307. exports.throwError = exports.left;
  308. /**
  309. * @category type lambdas
  310. * @since 2.0.0
  311. */
  312. exports.URI = 'ReaderEither';
  313. /**
  314. * @category filtering
  315. * @since 2.10.0
  316. */
  317. var getCompactable = function (M) {
  318. var C = E.getCompactable(M);
  319. return {
  320. URI: exports.URI,
  321. _E: undefined,
  322. compact: (0, Compactable_1.compact)(R.Functor, C),
  323. separate: (0, Compactable_1.separate)(R.Functor, C, E.Functor)
  324. };
  325. };
  326. exports.getCompactable = getCompactable;
  327. /**
  328. * @category filtering
  329. * @since 2.10.0
  330. */
  331. function getFilterable(M) {
  332. var F = E.getFilterable(M);
  333. var C = (0, exports.getCompactable)(M);
  334. var filter = (0, Filterable_1.filter)(R.Functor, F);
  335. var filterMap = (0, Filterable_1.filterMap)(R.Functor, F);
  336. var partition = (0, Filterable_1.partition)(R.Functor, F);
  337. var partitionMap = (0, Filterable_1.partitionMap)(R.Functor, F);
  338. return {
  339. URI: exports.URI,
  340. _E: undefined,
  341. map: _map,
  342. compact: C.compact,
  343. separate: C.separate,
  344. filter: function (fa, predicate) { return (0, function_1.pipe)(fa, filter(predicate)); },
  345. filterMap: function (fa, f) { return (0, function_1.pipe)(fa, filterMap(f)); },
  346. partition: function (fa, predicate) { return (0, function_1.pipe)(fa, partition(predicate)); },
  347. partitionMap: function (fa, f) { return (0, function_1.pipe)(fa, partitionMap(f)); }
  348. };
  349. }
  350. exports.getFilterable = getFilterable;
  351. /**
  352. * The default [`Applicative`](#applicative) instance returns the first error, if you want to
  353. * get all errors you need to provide a way to concatenate them via a `Semigroup`.
  354. *
  355. * See [`getApplicativeValidation`](./Either.ts.html#getapplicativevalidation).
  356. *
  357. * @category error handling
  358. * @since 2.7.0
  359. */
  360. function getApplicativeReaderValidation(S) {
  361. var ap = (0, Apply_1.ap)(R.Apply, E.getApplicativeValidation(S));
  362. return {
  363. URI: exports.URI,
  364. _E: undefined,
  365. map: _map,
  366. ap: function (fab, fa) { return (0, function_1.pipe)(fab, ap(fa)); },
  367. of: exports.of
  368. };
  369. }
  370. exports.getApplicativeReaderValidation = getApplicativeReaderValidation;
  371. /**
  372. * The default [`Alt`](#alt) instance returns the last error, if you want to
  373. * get all errors you need to provide a way to concatenate them via a `Semigroup`.
  374. *
  375. * See [`getAltValidation`](./Either.ts.html#getaltvalidation).
  376. *
  377. * @category error handling
  378. * @since 2.7.0
  379. */
  380. function getAltReaderValidation(S) {
  381. var alt = ET.altValidation(R.Monad, S);
  382. return {
  383. URI: exports.URI,
  384. _E: undefined,
  385. map: _map,
  386. alt: function (fa, that) { return (0, function_1.pipe)(fa, alt(that)); }
  387. };
  388. }
  389. exports.getAltReaderValidation = getAltReaderValidation;
  390. /**
  391. * @category instances
  392. * @since 2.7.0
  393. */
  394. exports.Functor = {
  395. URI: exports.URI,
  396. map: _map
  397. };
  398. /**
  399. * @category mapping
  400. * @since 2.10.0
  401. */
  402. exports.flap = (0, Functor_1.flap)(exports.Functor);
  403. /**
  404. * @category instances
  405. * @since 2.10.0
  406. */
  407. exports.Pointed = {
  408. URI: exports.URI,
  409. of: exports.of
  410. };
  411. /**
  412. * @category instances
  413. * @since 2.10.0
  414. */
  415. exports.Apply = {
  416. URI: exports.URI,
  417. map: _map,
  418. ap: _ap
  419. };
  420. /**
  421. * Combine two effectful actions, keeping only the result of the first.
  422. *
  423. * @since 2.0.0
  424. */
  425. exports.apFirst = (0, Apply_1.apFirst)(exports.Apply);
  426. /**
  427. * Less strict version of [`apFirst`](#apfirst)
  428. *
  429. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  430. *
  431. * @since 2.12.0
  432. */
  433. exports.apFirstW = exports.apFirst;
  434. /**
  435. * Combine two effectful actions, keeping only the result of the second.
  436. *
  437. * @since 2.0.0
  438. */
  439. exports.apSecond = (0, Apply_1.apSecond)(exports.Apply);
  440. /**
  441. * Less strict version of [`apSecond`](#apsecond)
  442. *
  443. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  444. *
  445. * @since 2.12.0
  446. */
  447. exports.apSecondW = exports.apSecond;
  448. /**
  449. * @category instances
  450. * @since 2.7.0
  451. */
  452. exports.Applicative = {
  453. URI: exports.URI,
  454. map: _map,
  455. ap: _ap,
  456. of: exports.of
  457. };
  458. /**
  459. * @category instances
  460. * @since 2.10.0
  461. */
  462. exports.Chain = {
  463. URI: exports.URI,
  464. map: _map,
  465. ap: _ap,
  466. chain: _chain
  467. };
  468. /**
  469. * @category instances
  470. * @since 2.7.0
  471. */
  472. exports.Monad = {
  473. URI: exports.URI,
  474. map: _map,
  475. ap: _ap,
  476. of: exports.of,
  477. chain: _chain
  478. };
  479. /**
  480. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  481. * keeping only the result of the first.
  482. *
  483. * @category sequencing
  484. * @since 2.0.0
  485. */
  486. exports.chainFirst = (0, Chain_1.chainFirst)(exports.Chain);
  487. /**
  488. * Less strict version of [`chainFirst`](#chainfirst)
  489. *
  490. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  491. *
  492. * @category sequencing
  493. * @since 2.8.0
  494. */
  495. exports.chainFirstW = exports.chainFirst;
  496. /**
  497. * @category instances
  498. * @since 2.7.0
  499. */
  500. exports.Bifunctor = {
  501. URI: exports.URI,
  502. bimap: _bimap,
  503. mapLeft: _mapLeft
  504. };
  505. /**
  506. * @category instances
  507. * @since 2.7.0
  508. */
  509. exports.Alt = {
  510. URI: exports.URI,
  511. map: _map,
  512. alt: _alt
  513. };
  514. /**
  515. * @category instances
  516. * @since 2.11.0
  517. */
  518. exports.FromReader = {
  519. URI: exports.URI,
  520. fromReader: exports.fromReader
  521. };
  522. /**
  523. * Reads the current context.
  524. *
  525. * @category constructors
  526. * @since 2.0.0
  527. */
  528. exports.ask = (0, FromReader_1.ask)(exports.FromReader);
  529. /**
  530. * Projects a value from the global context in a `ReaderEither`.
  531. *
  532. * @category constructors
  533. * @since 2.0.0
  534. */
  535. exports.asks = (0, FromReader_1.asks)(exports.FromReader);
  536. /**
  537. * @category lifting
  538. * @since 2.11.0
  539. */
  540. exports.fromReaderK = (0, FromReader_1.fromReaderK)(exports.FromReader);
  541. /**
  542. * @category sequencing
  543. * @since 2.11.0
  544. */
  545. exports.chainReaderK = (0, FromReader_1.chainReaderK)(exports.FromReader, exports.Chain);
  546. /**
  547. * Less strict version of [`chainReaderK`](#chainreaderk).
  548. *
  549. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  550. *
  551. * @category sequencing
  552. * @since 2.11.0
  553. */
  554. exports.chainReaderKW = exports.chainReaderK;
  555. /**
  556. * @category sequencing
  557. * @since 2.11.0
  558. */
  559. exports.chainFirstReaderK = (0, FromReader_1.chainFirstReaderK)(exports.FromReader, exports.Chain);
  560. /**
  561. * Less strict version of [`chainReaderK`](#chainreaderk).
  562. *
  563. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  564. *
  565. * @category sequencing
  566. * @since 2.11.0
  567. */
  568. exports.chainFirstReaderKW = exports.chainFirstReaderK;
  569. /**
  570. * @category instances
  571. * @since 2.7.0
  572. */
  573. exports.MonadThrow = {
  574. URI: exports.URI,
  575. map: _map,
  576. ap: _ap,
  577. of: exports.of,
  578. chain: _chain,
  579. throwError: exports.throwError
  580. };
  581. /**
  582. * @category instances
  583. * @since 2.10.0
  584. */
  585. exports.FromEither = {
  586. URI: exports.URI,
  587. fromEither: exports.fromEither
  588. };
  589. /**
  590. * @category conversions
  591. * @since 2.0.0
  592. */
  593. exports.fromOption =
  594. /*#__PURE__*/ (0, FromEither_1.fromOption)(exports.FromEither);
  595. /**
  596. * @category lifting
  597. * @since 2.10.0
  598. */
  599. exports.fromOptionK = (0, FromEither_1.fromOptionK)(exports.FromEither);
  600. /**
  601. * @category sequencing
  602. * @since 2.10.0
  603. */
  604. exports.chainOptionK =
  605. /*#__PURE__*/ (0, FromEither_1.chainOptionK)(exports.FromEither, exports.Chain);
  606. /**
  607. * @category sequencing
  608. * @since 2.4.0
  609. */
  610. exports.chainEitherK = (0, FromEither_1.chainEitherK)(exports.FromEither, exports.Chain);
  611. /**
  612. * Less strict version of [`chainEitherK`](#chaineitherk).
  613. *
  614. * The `W` suffix (short for **W**idening) means that the error types will be merged.
  615. *
  616. * @category sequencing
  617. * @since 2.6.1
  618. */
  619. exports.chainEitherKW = exports.chainEitherK;
  620. /**
  621. * @category sequencing
  622. * @since 2.12.0
  623. */
  624. exports.chainFirstEitherK = (0, FromEither_1.chainFirstEitherK)(exports.FromEither, exports.Chain);
  625. /**
  626. * Less strict version of [`chainFirstEitherK`](#chainfirsteitherk).
  627. *
  628. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  629. *
  630. * @category sequencing
  631. * @since 2.12.0
  632. */
  633. exports.chainFirstEitherKW = exports.chainFirstEitherK;
  634. /**
  635. * @category lifting
  636. * @since 2.0.0
  637. */
  638. exports.fromPredicate = (0, FromEither_1.fromPredicate)(exports.FromEither);
  639. /**
  640. * @category filtering
  641. * @since 2.0.0
  642. */
  643. exports.filterOrElse = (0, FromEither_1.filterOrElse)(exports.FromEither, exports.Chain);
  644. /**
  645. * Less strict version of [`filterOrElse`](#filterorelse).
  646. *
  647. * The `W` suffix (short for **W**idening) means that the error types will be merged.
  648. *
  649. * @category filtering
  650. * @since 2.9.0
  651. */
  652. exports.filterOrElseW = exports.filterOrElse;
  653. /**
  654. * @category lifting
  655. * @since 2.4.0
  656. */
  657. exports.fromEitherK = (0, FromEither_1.fromEitherK)(exports.FromEither);
  658. // -------------------------------------------------------------------------------------
  659. // do notation
  660. // -------------------------------------------------------------------------------------
  661. /**
  662. * @category do notation
  663. * @since 2.9.0
  664. */
  665. exports.Do = (0, exports.of)(_.emptyRecord);
  666. /**
  667. * @category do notation
  668. * @since 2.8.0
  669. */
  670. exports.bindTo = (0, Functor_1.bindTo)(exports.Functor);
  671. var let_ = /*#__PURE__*/ (0, Functor_1.let)(exports.Functor);
  672. exports.let = let_;
  673. /**
  674. * @category do notation
  675. * @since 2.8.0
  676. */
  677. exports.bind = (0, Chain_1.bind)(exports.Chain);
  678. /**
  679. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  680. *
  681. * @category do notation
  682. * @since 2.8.0
  683. */
  684. exports.bindW = exports.bind;
  685. /**
  686. * @category do notation
  687. * @since 2.8.0
  688. */
  689. exports.apS = (0, Apply_1.apS)(exports.Apply);
  690. /**
  691. * Less strict version of [`apS`](#aps).
  692. *
  693. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  694. *
  695. * @category do notation
  696. * @since 2.8.0
  697. */
  698. exports.apSW = exports.apS;
  699. /**
  700. * @since 2.11.0
  701. */
  702. exports.ApT = (0, exports.of)(_.emptyReadonlyArray);
  703. // -------------------------------------------------------------------------------------
  704. // array utils
  705. // -------------------------------------------------------------------------------------
  706. /**
  707. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  708. *
  709. * @category traversing
  710. * @since 2.11.0
  711. */
  712. var traverseReadonlyNonEmptyArrayWithIndex = function (f) {
  713. return (0, function_1.flow)(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(E.traverseReadonlyNonEmptyArrayWithIndex(function_1.SK)));
  714. };
  715. exports.traverseReadonlyNonEmptyArrayWithIndex = traverseReadonlyNonEmptyArrayWithIndex;
  716. /**
  717. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  718. *
  719. * @category traversing
  720. * @since 2.11.0
  721. */
  722. var traverseReadonlyArrayWithIndex = function (f) {
  723. var g = (0, exports.traverseReadonlyNonEmptyArrayWithIndex)(f);
  724. return function (as) { return (_.isNonEmpty(as) ? g(as) : exports.ApT); };
  725. };
  726. exports.traverseReadonlyArrayWithIndex = traverseReadonlyArrayWithIndex;
  727. /**
  728. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  729. *
  730. * @category traversing
  731. * @since 2.9.0
  732. */
  733. exports.traverseArrayWithIndex = exports.traverseReadonlyArrayWithIndex;
  734. /**
  735. * Equivalent to `ReadonlyArray#traverse(Applicative)`.
  736. *
  737. * @category traversing
  738. * @since 2.9.0
  739. */
  740. var traverseArray = function (f) { return (0, exports.traverseReadonlyArrayWithIndex)(function (_, a) { return f(a); }); };
  741. exports.traverseArray = traverseArray;
  742. /**
  743. * Equivalent to `ReadonlyArray#sequence(Applicative)`.
  744. *
  745. * @category traversing
  746. * @since 2.9.0
  747. */
  748. exports.sequenceArray = (0, exports.traverseArray)(function_1.identity);
  749. // -------------------------------------------------------------------------------------
  750. // deprecated
  751. // -------------------------------------------------------------------------------------
  752. /**
  753. * This instance is deprecated, use small, specific instances instead.
  754. * For example if a function needs a `Functor` instance, pass `RE.Functor` instead of `RE.readerEither`
  755. * (where `R` is from `import R from 'fp-ts/ReaderEither'`)
  756. *
  757. * @category zone of death
  758. * @since 2.0.0
  759. * @deprecated
  760. */
  761. exports.readerEither = {
  762. URI: exports.URI,
  763. bimap: _bimap,
  764. mapLeft: _mapLeft,
  765. map: _map,
  766. of: exports.of,
  767. ap: _ap,
  768. chain: _chain,
  769. alt: _alt,
  770. throwError: exports.left
  771. };
  772. /**
  773. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  774. *
  775. * @category zone of death
  776. * @since 2.0.0
  777. * @deprecated
  778. */
  779. exports.getApplySemigroup =
  780. /*#__PURE__*/ (0, Apply_1.getApplySemigroup)(exports.Apply);
  781. /**
  782. * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead.
  783. *
  784. * @category zone of death
  785. * @since 2.0.0
  786. * @deprecated
  787. */
  788. exports.getApplyMonoid =
  789. /*#__PURE__*/ (0, Applicative_1.getApplicativeMonoid)(exports.Applicative);
  790. /**
  791. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  792. *
  793. * @category zone of death
  794. * @since 2.0.0
  795. * @deprecated
  796. */
  797. var getSemigroup = function (S) {
  798. return (0, Apply_1.getApplySemigroup)(R.Apply)(E.getSemigroup(S));
  799. };
  800. exports.getSemigroup = getSemigroup;
  801. /**
  802. * Use [`getApplicativeReaderValidation`](#getapplicativereadervalidation) and [`getAltReaderValidation`](#getaltreadervalidation) instead.
  803. *
  804. * @category zone of death
  805. * @since 2.3.0
  806. * @deprecated
  807. */
  808. function getReaderValidation(SE) {
  809. var applicativeReaderValidation = getApplicativeReaderValidation(SE);
  810. var altReaderValidation = getAltReaderValidation(SE);
  811. return {
  812. URI: exports.URI,
  813. _E: undefined,
  814. map: _map,
  815. ap: applicativeReaderValidation.ap,
  816. of: exports.of,
  817. chain: _chain,
  818. bimap: _bimap,
  819. mapLeft: _mapLeft,
  820. alt: altReaderValidation.alt,
  821. throwError: exports.throwError
  822. };
  823. }
  824. exports.getReaderValidation = getReaderValidation;