版博士V2.0程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

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