版博士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.
 
 
 
 

909 lines
22 KiB

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