版博士V2.0程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

1258 rader
32 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 { ask as ask_, asks as asks_, chainFirstReaderK as chainFirstReaderK_, chainReaderK as chainReaderK_, fromReaderK as fromReaderK_ } from './FromReader';
  11. import { chainFirstTaskK as chainFirstTaskK_, chainTaskK as chainTaskK_, fromTaskK as fromTaskK_ } from './FromTask';
  12. import { flow, identity, pipe, SK } from './function';
  13. import { bindTo as bindTo_, flap as flap_, let as let__ } from './Functor';
  14. import * as _ from './internal';
  15. import * as R from './Reader';
  16. import * as RT from './ReaderTask';
  17. import * as T from './Task';
  18. import * as TE from './TaskEither';
  19. // -------------------------------------------------------------------------------------
  20. // constructors
  21. // -------------------------------------------------------------------------------------
  22. /**
  23. * @category conversions
  24. * @since 2.0.0
  25. */
  26. export var fromTaskEither = /*#__PURE__*/ R.of;
  27. /**
  28. * @category constructors
  29. * @since 2.0.0
  30. */
  31. export var left = /*#__PURE__*/ ET.left(RT.Pointed);
  32. /**
  33. * @category constructors
  34. * @since 2.0.0
  35. */
  36. export var right = /*#__PURE__*/ ET.right(RT.Pointed);
  37. /**
  38. * @category constructors
  39. * @since 2.0.0
  40. */
  41. export var rightTask = /*#__PURE__*/ flow(TE.rightTask, fromTaskEither);
  42. /**
  43. * @category constructors
  44. * @since 2.0.0
  45. */
  46. export var leftTask = /*#__PURE__*/ flow(TE.leftTask, fromTaskEither);
  47. /**
  48. * @category constructors
  49. * @since 2.0.0
  50. */
  51. export var rightReader = function (ma) {
  52. return flow(ma, TE.right);
  53. };
  54. /**
  55. * @category constructors
  56. * @since 2.0.0
  57. */
  58. export var leftReader = function (me) {
  59. return flow(me, TE.left);
  60. };
  61. /**
  62. * @category constructors
  63. * @since 2.5.0
  64. */
  65. export var rightReaderTask =
  66. /*#__PURE__*/ ET.rightF(RT.Functor);
  67. /**
  68. * @category constructors
  69. * @since 2.5.0
  70. */
  71. export var leftReaderTask =
  72. /*#__PURE__*/ ET.leftF(RT.Functor);
  73. /**
  74. * @category constructors
  75. * @since 2.0.0
  76. */
  77. export var rightIO = /*#__PURE__*/ flow(TE.rightIO, fromTaskEither);
  78. /**
  79. * @category constructors
  80. * @since 2.0.0
  81. */
  82. export var leftIO = /*#__PURE__*/ flow(TE.leftIO, fromTaskEither);
  83. /**
  84. * @category constructors
  85. * @since 2.13.0
  86. */
  87. export var rightReaderIO = /*#__PURE__*/ function (ma) { return flow(ma, TE.rightIO); };
  88. /**
  89. * @category constructors
  90. * @since 2.13.0
  91. */
  92. export var leftReaderIO = /*#__PURE__*/ function (me) { return flow(me, TE.leftIO); };
  93. // -------------------------------------------------------------------------------------
  94. // conversions
  95. // -------------------------------------------------------------------------------------
  96. /**
  97. * @category conversions
  98. * @since 2.0.0
  99. */
  100. export var fromEither = RT.of;
  101. /**
  102. * @category conversions
  103. * @since 2.11.0
  104. */
  105. export var fromReader = rightReader;
  106. /**
  107. * @category conversions
  108. * @since 2.0.0
  109. */
  110. export var fromIO = rightIO;
  111. /**
  112. * @category conversions
  113. * @since 2.0.0
  114. */
  115. export var fromTask = rightTask;
  116. /**
  117. * @category conversions
  118. * @since 2.0.0
  119. */
  120. export var fromIOEither = /*#__PURE__*/ flow(TE.fromIOEither, fromTaskEither);
  121. /**
  122. * @category conversions
  123. * @since 2.0.0
  124. */
  125. export var fromReaderEither = function (ma) {
  126. return flow(ma, TE.fromEither);
  127. };
  128. /**
  129. * @category pattern matching
  130. * @since 2.10.0
  131. */
  132. export var match = /*#__PURE__*/ ET.match(RT.Functor);
  133. /**
  134. * Less strict version of [`match`](#match).
  135. *
  136. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  137. *
  138. * @category pattern matching
  139. * @since 2.10.0
  140. */
  141. export var matchW = match;
  142. /**
  143. * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`ReaderTask`).
  144. *
  145. * @category pattern matching
  146. * @since 2.10.0
  147. */
  148. export var matchE = /*#__PURE__*/ ET.matchE(RT.Chain);
  149. /**
  150. * Alias of [`matchE`](#matche).
  151. *
  152. * @category pattern matching
  153. * @since 2.0.0
  154. */
  155. export var fold = matchE;
  156. /**
  157. * Less strict version of [`matchE`](#matche).
  158. *
  159. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  160. *
  161. * @category pattern matching
  162. * @since 2.10.0
  163. */
  164. export var matchEW = matchE;
  165. /**
  166. * Alias of [`matchEW`](#matchew).
  167. *
  168. * @category pattern matching
  169. * @since 2.10.0
  170. */
  171. export var foldW = matchEW;
  172. /**
  173. * @category error handling
  174. * @since 2.0.0
  175. */
  176. export var getOrElse = /*#__PURE__*/ ET.getOrElse(RT.Monad);
  177. /**
  178. * Less strict version of [`getOrElse`](#getorelse).
  179. *
  180. * The `W` suffix (short for **W**idening) means that the handler return type will be merged.
  181. *
  182. * @category error handling
  183. * @since 2.6.0
  184. */
  185. export var getOrElseW = getOrElse;
  186. /**
  187. * @category conversions
  188. * @since 2.10.0
  189. */
  190. export var toUnion = /*#__PURE__*/ ET.toUnion(RT.Functor);
  191. /**
  192. * @category conversions
  193. * @since 2.12.0
  194. */
  195. export var fromNullable =
  196. /*#__PURE__*/ ET.fromNullable(RT.Pointed);
  197. /**
  198. * @category lifting
  199. * @since 2.12.0
  200. */
  201. export var fromNullableK = /*#__PURE__*/ ET.fromNullableK(RT.Pointed);
  202. /**
  203. * @category sequencing
  204. * @since 2.12.0
  205. */
  206. export var chainNullableK = /*#__PURE__*/ ET.chainNullableK(RT.Monad);
  207. // -------------------------------------------------------------------------------------
  208. // combinators
  209. // -------------------------------------------------------------------------------------
  210. /**
  211. * Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s
  212. * `contramap`).
  213. *
  214. * @since 2.0.0
  215. */
  216. export var local = R.local;
  217. /**
  218. * Less strict version of [`asksReaderTaskEither`](#asksreadertaskeither).
  219. *
  220. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  221. *
  222. * @category constructors
  223. * @since 2.11.0
  224. */
  225. export var asksReaderTaskEitherW = R.asksReaderW;
  226. /**
  227. * Effectfully accesses the environment.
  228. *
  229. * @category constructors
  230. * @since 2.11.0
  231. */
  232. export var asksReaderTaskEither = asksReaderTaskEitherW;
  233. /**
  234. * @category error handling
  235. * @since 2.0.0
  236. */
  237. export var orElse = /*#__PURE__*/ ET.orElse(RT.Monad);
  238. /**
  239. * Less strict version of [`orElse`](#orelse).
  240. *
  241. * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged.
  242. *
  243. * @category error handling
  244. * @since 2.10.0
  245. */
  246. export var orElseW = orElse;
  247. /**
  248. * @category error handling
  249. * @since 2.11.0
  250. */
  251. export var orElseFirst = /*#__PURE__*/ ET.orElseFirst(RT.Monad);
  252. /**
  253. * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged.
  254. *
  255. * @category error handling
  256. * @since 2.11.0
  257. */
  258. export var orElseFirstW = orElseFirst;
  259. /**
  260. * @category error handling
  261. * @since 2.11.0
  262. */
  263. export var orLeft = /*#__PURE__*/ ET.orLeft(RT.Monad);
  264. /**
  265. * @since 2.0.0
  266. */
  267. export var swap = /*#__PURE__*/ ET.swap(RT.Functor);
  268. /**
  269. * @category lifting
  270. * @since 2.4.0
  271. */
  272. export var fromIOEitherK = function (f) { return flow(f, fromIOEither); };
  273. /**
  274. * Less strict version of [`chainIOEitherK`](#chainioeitherk).
  275. *
  276. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  277. *
  278. * @category sequencing
  279. * @since 2.6.1
  280. */
  281. export var chainIOEitherKW = function (f) { return chainW(fromIOEitherK(f)); };
  282. /**
  283. * @category sequencing
  284. * @since 2.4.0
  285. */
  286. export var chainIOEitherK = chainIOEitherKW;
  287. /**
  288. * @category lifting
  289. * @since 2.4.0
  290. */
  291. export var fromTaskEitherK = function (f) { return flow(f, fromTaskEither); };
  292. /**
  293. * Less strict version of [`chainTaskEitherK`](#chaintaskeitherk).
  294. *
  295. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  296. *
  297. * @category sequencing
  298. * @since 2.6.1
  299. */
  300. export var chainTaskEitherKW = function (f) { return chainW(fromTaskEitherK(f)); };
  301. /**
  302. * @category sequencing
  303. * @since 2.4.0
  304. */
  305. export var chainTaskEitherK = chainTaskEitherKW;
  306. /**
  307. * Less strict version of [`chainFirstTaskEitherK`](#chainfirsttaskeitherk).
  308. *
  309. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  310. *
  311. * @category sequencing
  312. * @since 2.11.0
  313. */
  314. export var chainFirstTaskEitherKW = function (f) { return chainFirstW(fromTaskEitherK(f)); };
  315. /**
  316. * @category sequencing
  317. * @since 2.11.0
  318. */
  319. export var chainFirstTaskEitherK = chainFirstTaskEitherKW;
  320. /**
  321. * @category lifting
  322. * @since 2.11.0
  323. */
  324. export var fromReaderEitherK = function (f) { return flow(f, fromReaderEither); };
  325. /**
  326. * Less strict version of [`chainReaderEitherK`](#chainreadereitherk).
  327. *
  328. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  329. *
  330. * @category sequencing
  331. * @since 2.11.0
  332. */
  333. export var chainReaderEitherKW = function (f) {
  334. return chainW(fromReaderEitherK(f));
  335. };
  336. /**
  337. * @category sequencing
  338. * @since 2.11.0
  339. */
  340. export var chainReaderEitherK = chainReaderEitherKW;
  341. /**
  342. * Less strict version of [`chainFirstReaderEitherK`](#chainfirstreadereitherk).
  343. *
  344. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  345. *
  346. * @category sequencing
  347. * @since 2.11.0
  348. */
  349. export var chainFirstReaderEitherKW = function (f) {
  350. return chainFirstW(fromReaderEitherK(f));
  351. };
  352. /**
  353. * @category sequencing
  354. * @since 2.11.0
  355. */
  356. export var chainFirstReaderEitherK = chainFirstReaderEitherKW;
  357. var _map = function (fa, f) { return pipe(fa, map(f)); };
  358. var _apPar = function (fab, fa) { return pipe(fab, ap(fa)); };
  359. var _apSeq = function (fab, fa) {
  360. return pipe(fab, chain(function (f) { return pipe(fa, map(f)); }));
  361. };
  362. /* istanbul ignore next */
  363. var _chain = function (ma, f) { return pipe(ma, chain(f)); };
  364. /* istanbul ignore next */
  365. var _alt = function (fa, that) { return pipe(fa, alt(that)); };
  366. /* istanbul ignore next */
  367. var _bimap = function (fa, f, g) { return pipe(fa, bimap(f, g)); };
  368. /* istanbul ignore next */
  369. var _mapLeft = function (fa, f) { return pipe(fa, mapLeft(f)); };
  370. /**
  371. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  372. * use the type constructor `F` to represent some computational context.
  373. *
  374. * @category mapping
  375. * @since 2.0.0
  376. */
  377. export var map =
  378. /*#__PURE__*/ ET.map(RT.Functor);
  379. /**
  380. * Map a pair of functions over the two last type arguments of the bifunctor.
  381. *
  382. * @category mapping
  383. * @since 2.0.0
  384. */
  385. export var bimap = /*#__PURE__*/ ET.bimap(RT.Functor);
  386. /**
  387. * Map a function over the second type argument of a bifunctor.
  388. *
  389. * @category error handling
  390. * @since 2.0.0
  391. */
  392. export var mapLeft =
  393. /*#__PURE__*/ ET.mapLeft(RT.Functor);
  394. /**
  395. * @since 2.0.0
  396. */
  397. export var ap = /*#__PURE__*/ ET.ap(RT.ApplyPar);
  398. /**
  399. * Less strict version of [`ap`](#ap).
  400. *
  401. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  402. *
  403. * @since 2.8.0
  404. */
  405. export var apW = ap;
  406. /**
  407. * @category constructors
  408. * @since 2.7.0
  409. */
  410. export var of = right;
  411. /**
  412. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  413. *
  414. * @category sequencing
  415. * @since 2.0.0
  416. */
  417. export var chain = /*#__PURE__*/ ET.chain(RT.Monad);
  418. /**
  419. * Less strict version of [`chain`](#chain).
  420. *
  421. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  422. *
  423. * @category sequencing
  424. * @since 2.6.0
  425. */
  426. export var chainW = chain;
  427. /**
  428. * Less strict version of [`flatten`](#flatten).
  429. *
  430. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  431. *
  432. * @category sequencing
  433. * @since 2.11.0
  434. */
  435. export var flattenW = /*#__PURE__*/ chainW(identity);
  436. /**
  437. * @category sequencing
  438. * @since 2.0.0
  439. */
  440. export var flatten = flattenW;
  441. /**
  442. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  443. * types of kind `* -> *`.
  444. *
  445. * @category error handling
  446. * @since 2.0.0
  447. */
  448. export var alt = /*#__PURE__*/ ET.alt(RT.Monad);
  449. /**
  450. * Less strict version of [`alt`](#alt).
  451. *
  452. * The `W` suffix (short for **W**idening) means that the environment, the error and the return types will be merged.
  453. *
  454. * @category error handling
  455. * @since 2.9.0
  456. */
  457. export var altW = alt;
  458. /**
  459. * @since 2.0.0
  460. */
  461. export var throwError = left;
  462. /**
  463. * @category type lambdas
  464. * @since 2.0.0
  465. */
  466. export var URI = 'ReaderTaskEither';
  467. /**
  468. * @category filtering
  469. * @since 2.10.0
  470. */
  471. export var getCompactable = function (M) {
  472. var C = E.getCompactable(M);
  473. return {
  474. URI: URI,
  475. _E: undefined,
  476. compact: compact_(RT.Functor, C),
  477. separate: separate_(RT.Functor, C, E.Functor)
  478. };
  479. };
  480. /**
  481. * @category filtering
  482. * @since 2.10.0
  483. */
  484. export function getFilterable(M) {
  485. var F = E.getFilterable(M);
  486. var C = getCompactable(M);
  487. var filter = filter_(RT.Functor, F);
  488. var filterMap = filterMap_(RT.Functor, F);
  489. var partition = partition_(RT.Functor, F);
  490. var partitionMap = partitionMap_(RT.Functor, F);
  491. return {
  492. URI: URI,
  493. _E: undefined,
  494. map: _map,
  495. compact: C.compact,
  496. separate: C.separate,
  497. filter: function (fa, predicate) { return pipe(fa, filter(predicate)); },
  498. filterMap: function (fa, f) { return pipe(fa, filterMap(f)); },
  499. partition: function (fa, predicate) { return pipe(fa, partition(predicate)); },
  500. partitionMap: function (fa, f) { return pipe(fa, partitionMap(f)); }
  501. };
  502. }
  503. /**
  504. * The default [`ApplicativePar`](#applicativepar) instance returns the first error, if you want to
  505. * get all errors you need to provide a way to concatenate them via a `Semigroup`.
  506. *
  507. * See [`getApplicativeValidation`](./Either.ts.html#getapplicativevalidation).
  508. *
  509. * @category error handling
  510. * @since 2.7.0
  511. */
  512. export function getApplicativeReaderTaskValidation(A, S) {
  513. var ap = ap_(R.Apply, TE.getApplicativeTaskValidation(A, S));
  514. return {
  515. URI: URI,
  516. _E: undefined,
  517. map: _map,
  518. ap: function (fab, fa) { return pipe(fab, ap(fa)); },
  519. of: of
  520. };
  521. }
  522. /**
  523. * The default [`Alt`](#alt) instance returns the last error, if you want to
  524. * get all errors you need to provide a way to concatenate them via a `Semigroup`.
  525. *
  526. * See [`getAltValidation`](./Either.ts.html#getaltvalidation).
  527. *
  528. * @category error handling
  529. * @since 2.7.0
  530. */
  531. export function getAltReaderTaskValidation(S) {
  532. var alt = ET.altValidation(RT.Monad, S);
  533. return {
  534. URI: URI,
  535. _E: undefined,
  536. map: _map,
  537. alt: function (fa, that) { return pipe(fa, alt(that)); }
  538. };
  539. }
  540. /**
  541. * @category instances
  542. * @since 2.7.0
  543. */
  544. export var Functor = {
  545. URI: URI,
  546. map: _map
  547. };
  548. /**
  549. * @category mapping
  550. * @since 2.10.0
  551. */
  552. export var flap = /*#__PURE__*/ flap_(Functor);
  553. /**
  554. * @category instances
  555. * @since 2.10.0
  556. */
  557. export var Pointed = {
  558. URI: URI,
  559. of: of
  560. };
  561. /**
  562. * Runs computations in parallel.
  563. *
  564. * @category instances
  565. * @since 2.10.0
  566. */
  567. export var ApplyPar = {
  568. URI: URI,
  569. map: _map,
  570. ap: _apPar
  571. };
  572. /**
  573. * Combine two effectful actions, keeping only the result of the first.
  574. *
  575. * @since 2.0.0
  576. */
  577. export var apFirst = /*#__PURE__*/ apFirst_(ApplyPar);
  578. /**
  579. * Less strict version of [`apFirst`](#apfirst).
  580. *
  581. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  582. *
  583. * @since 2.12.0
  584. */
  585. export var apFirstW = apFirst;
  586. /**
  587. * Combine two effectful actions, keeping only the result of the second.
  588. *
  589. * @since 2.0.0
  590. */
  591. export var apSecond = /*#__PURE__*/ apSecond_(ApplyPar);
  592. /**
  593. * Less strict version of [`apSecond`](#apsecond).
  594. *
  595. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  596. *
  597. * @since 2.12.0
  598. */
  599. export var apSecondW = apSecond;
  600. /**
  601. * Runs computations in parallel.
  602. *
  603. * @category instances
  604. * @since 2.7.0
  605. */
  606. export var ApplicativePar = {
  607. URI: URI,
  608. map: _map,
  609. ap: _apPar,
  610. of: of
  611. };
  612. /**
  613. * Runs computations sequentially.
  614. *
  615. * @category instances
  616. * @since 2.10.0
  617. */
  618. export var ApplySeq = {
  619. URI: URI,
  620. map: _map,
  621. ap: _apSeq
  622. };
  623. /**
  624. * Runs computations sequentially.
  625. *
  626. * @category instances
  627. * @since 2.7.0
  628. */
  629. export var ApplicativeSeq = {
  630. URI: URI,
  631. map: _map,
  632. ap: _apSeq,
  633. of: of
  634. };
  635. /**
  636. * @category instances
  637. * @since 2.10.0
  638. */
  639. export var Chain = {
  640. URI: URI,
  641. map: _map,
  642. ap: _apPar,
  643. chain: _chain
  644. };
  645. /**
  646. * @category instances
  647. * @since 2.10.0
  648. */
  649. export var Monad = {
  650. URI: URI,
  651. map: _map,
  652. ap: _apPar,
  653. chain: _chain,
  654. of: of
  655. };
  656. /**
  657. * @category instances
  658. * @since 2.10.0
  659. */
  660. export var MonadIO = {
  661. URI: URI,
  662. map: _map,
  663. ap: _apPar,
  664. chain: _chain,
  665. of: of,
  666. fromIO: fromIO
  667. };
  668. /**
  669. * @category instances
  670. * @since 2.10.0
  671. */
  672. export var MonadTask = {
  673. URI: URI,
  674. map: _map,
  675. ap: _apPar,
  676. chain: _chain,
  677. of: of,
  678. fromIO: fromIO,
  679. fromTask: fromTask
  680. };
  681. /**
  682. * @category instances
  683. * @since 2.10.0
  684. */
  685. export var MonadThrow = {
  686. URI: URI,
  687. map: _map,
  688. ap: _apPar,
  689. chain: _chain,
  690. of: of,
  691. throwError: throwError
  692. };
  693. /**
  694. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  695. * keeping only the result of the first.
  696. *
  697. * @category sequencing
  698. * @since 2.0.0
  699. */
  700. export var chainFirst = /*#__PURE__*/ chainFirst_(Chain);
  701. /**
  702. * Less strict version of [`chainFirst`](#chainfirst).
  703. *
  704. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  705. *
  706. * @category sequencing
  707. * @since 2.8.0
  708. */
  709. export var chainFirstW = chainFirst;
  710. /**
  711. * @category instances
  712. * @since 2.7.0
  713. */
  714. export var Bifunctor = {
  715. URI: URI,
  716. bimap: _bimap,
  717. mapLeft: _mapLeft
  718. };
  719. /**
  720. * @category instances
  721. * @since 2.7.0
  722. */
  723. export var Alt = {
  724. URI: URI,
  725. map: _map,
  726. alt: _alt
  727. };
  728. /**
  729. * @category instances
  730. * @since 2.11.0
  731. */
  732. export var FromReader = {
  733. URI: URI,
  734. fromReader: fromReader
  735. };
  736. /**
  737. * Reads the current context.
  738. *
  739. * @category constructors
  740. * @since 2.0.0
  741. */
  742. export var ask = /*#__PURE__*/ ask_(FromReader);
  743. /**
  744. * Projects a value from the global context in a `ReaderEither`.
  745. *
  746. * @category constructors
  747. * @since 2.0.0
  748. */
  749. export var asks = /*#__PURE__*/ asks_(FromReader);
  750. /**
  751. * @category lifting
  752. * @since 2.11.0
  753. */
  754. export var fromReaderK = /*#__PURE__*/ fromReaderK_(FromReader);
  755. /**
  756. * @category sequencing
  757. * @since 2.11.0
  758. */
  759. export var chainReaderK = /*#__PURE__*/ chainReaderK_(FromReader, Chain);
  760. /**
  761. * Less strict version of [`chainReaderK`](#chainreaderk).
  762. *
  763. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  764. *
  765. * @category sequencing
  766. * @since 2.11.0
  767. */
  768. export var chainReaderKW = chainReaderK;
  769. /**
  770. * @category sequencing
  771. * @since 2.11.0
  772. */
  773. export var chainFirstReaderK = /*#__PURE__*/ chainFirstReaderK_(FromReader, Chain);
  774. /**
  775. * Less strict version of [`chainFirstReaderK`](#chainfirstreaderk).
  776. *
  777. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  778. *
  779. * @category sequencing
  780. * @since 2.11.0
  781. */
  782. export var chainFirstReaderKW = chainFirstReaderK;
  783. /**
  784. * @category lifting
  785. * @since 2.11.0
  786. */
  787. export var fromReaderTaskK = function (f) {
  788. return function () {
  789. var a = [];
  790. for (var _i = 0; _i < arguments.length; _i++) {
  791. a[_i] = arguments[_i];
  792. }
  793. return rightReaderTask(f.apply(void 0, a));
  794. };
  795. };
  796. /**
  797. * Less strict version of [`chainReaderTaskK`](#chainreadertaskk).
  798. *
  799. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  800. *
  801. * @category sequencing
  802. * @since 2.11.0
  803. */
  804. export var chainReaderTaskKW = function (f) { return chainW(fromReaderTaskK(f)); };
  805. /**
  806. * @category sequencing
  807. * @since 2.11.0
  808. */
  809. export var chainReaderTaskK = chainReaderTaskKW;
  810. /**
  811. * Less strict version of [`chainFirstReaderTaskK`](#chainfirstreadertaskk).
  812. *
  813. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  814. *
  815. * @category sequencing
  816. * @since 2.11.0
  817. */
  818. export var chainFirstReaderTaskKW = function (f) { return chainFirstW(fromReaderTaskK(f)); };
  819. /**
  820. * @category sequencing
  821. * @since 2.11.0
  822. */
  823. export var chainFirstReaderTaskK = chainFirstReaderTaskKW;
  824. /**
  825. * @category lifting
  826. * @since 2.13.0
  827. */
  828. export var fromReaderIOK = function (f) {
  829. return function () {
  830. var a = [];
  831. for (var _i = 0; _i < arguments.length; _i++) {
  832. a[_i] = arguments[_i];
  833. }
  834. return rightReaderIO(f.apply(void 0, a));
  835. };
  836. };
  837. /**
  838. * Less strict version of [`chainReaderIOK`](#chainreaderiok).
  839. *
  840. * @category sequencing
  841. * @since 2.13.0
  842. */
  843. export var chainReaderIOKW = function (f) { return chainW(fromReaderIOK(f)); };
  844. /**
  845. * @category sequencing
  846. * @since 2.13.0
  847. */
  848. export var chainReaderIOK = chainReaderIOKW;
  849. /**
  850. * Less strict version of [`chainFirstReaderIOK`](#chainfirstreaderiok).
  851. *
  852. * @category sequencing
  853. * @since 2.13.0
  854. */
  855. export var chainFirstReaderIOKW = function (f) { return chainFirstW(fromReaderIOK(f)); };
  856. /**
  857. * @category sequencing
  858. * @since 2.13.0
  859. */
  860. export var chainFirstReaderIOK = chainFirstReaderIOKW;
  861. /**
  862. * @category instances
  863. * @since 2.10.0
  864. */
  865. export var FromEither = {
  866. URI: URI,
  867. fromEither: fromEither
  868. };
  869. /**
  870. * @category conversions
  871. * @since 2.0.0
  872. */
  873. export var fromOption =
  874. /*#__PURE__*/ fromOption_(FromEither);
  875. /**
  876. * @category lifting
  877. * @since 2.10.0
  878. */
  879. export var fromOptionK = /*#__PURE__*/ fromOptionK_(FromEither);
  880. /**
  881. * @category sequencing
  882. * @since 2.10.0
  883. */
  884. export var chainOptionK =
  885. /*#__PURE__*/ chainOptionK_(FromEither, Chain);
  886. /**
  887. * @category sequencing
  888. * @since 2.4.0
  889. */
  890. export var chainEitherK = /*#__PURE__*/ chainEitherK_(FromEither, Chain);
  891. /**
  892. * Less strict version of [`chainEitherK`](#chaineitherk).
  893. *
  894. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  895. *
  896. * @category sequencing
  897. * @since 2.6.1
  898. */
  899. export var chainEitherKW = chainEitherK;
  900. /**
  901. * @category sequencing
  902. * @since 2.12.0
  903. */
  904. export var chainFirstEitherK = /*#__PURE__*/ chainFirstEitherK_(FromEither, Chain);
  905. /**
  906. * Less strict version of [`chainFirstEitherK`](#chainfirsteitherk).
  907. *
  908. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  909. *
  910. * @category sequencing
  911. * @since 2.12.0
  912. */
  913. export var chainFirstEitherKW = chainFirstEitherK;
  914. /**
  915. * @category lifting
  916. * @since 2.0.0
  917. */
  918. export var fromPredicate = /*#__PURE__*/ fromPredicate_(FromEither);
  919. /**
  920. * @category filtering
  921. * @since 2.0.0
  922. */
  923. export var filterOrElse = /*#__PURE__*/ filterOrElse_(FromEither, Chain);
  924. /**
  925. * Less strict version of [`filterOrElse`](#filterorelse).
  926. *
  927. * The `W` suffix (short for **W**idening) means that the error types will be merged.
  928. *
  929. * @category filtering
  930. * @since 2.9.0
  931. */
  932. export var filterOrElseW = filterOrElse;
  933. /**
  934. * @category lifting
  935. * @since 2.4.0
  936. */
  937. export var fromEitherK = /*#__PURE__*/ fromEitherK_(FromEither);
  938. /**
  939. * @category instances
  940. * @since 2.10.0
  941. */
  942. export var FromIO = {
  943. URI: URI,
  944. fromIO: fromIO
  945. };
  946. /**
  947. * @category lifting
  948. * @since 2.10.0
  949. */
  950. export var fromIOK = /*#__PURE__*/ fromIOK_(FromIO);
  951. /**
  952. * @category sequencing
  953. * @since 2.10.0
  954. */
  955. export var chainIOK = /*#__PURE__*/ chainIOK_(FromIO, Chain);
  956. /**
  957. * @category sequencing
  958. * @since 2.10.0
  959. */
  960. export var chainFirstIOK = /*#__PURE__*/ chainFirstIOK_(FromIO, Chain);
  961. /**
  962. * @category instances
  963. * @since 2.10.0
  964. */
  965. export var FromTask = {
  966. URI: URI,
  967. fromIO: fromIO,
  968. fromTask: fromTask
  969. };
  970. /**
  971. * @category lifting
  972. * @since 2.10.0
  973. */
  974. export var fromTaskK = /*#__PURE__*/ fromTaskK_(FromTask);
  975. /**
  976. * @category sequencing
  977. * @since 2.10.0
  978. */
  979. export var chainTaskK = /*#__PURE__*/ chainTaskK_(FromTask, Chain);
  980. /**
  981. * @category sequencing
  982. * @since 2.10.0
  983. */
  984. export var chainFirstTaskK = /*#__PURE__*/ chainFirstTaskK_(FromTask, Chain);
  985. // -------------------------------------------------------------------------------------
  986. // utils
  987. // -------------------------------------------------------------------------------------
  988. /**
  989. * Make sure that a resource is cleaned up in the event of an exception (\*). The release action is called regardless of
  990. * whether the body action throws (\*) or returns.
  991. *
  992. * (\*) i.e. returns a `Left`
  993. *
  994. * @since 2.0.4
  995. */
  996. export function bracket(acquire, use, release) {
  997. return bracketW(acquire, use, release);
  998. }
  999. /**
  1000. * Less strict version of [`bracket`](#bracket).
  1001. *
  1002. * @since 2.12.0
  1003. */
  1004. export function bracketW(acquire, use, release) {
  1005. return function (r) {
  1006. return TE.bracketW(acquire(r), function (a) { return use(a)(r); }, function (a, e) { return release(a, e)(r); });
  1007. };
  1008. }
  1009. // -------------------------------------------------------------------------------------
  1010. // do notation
  1011. // -------------------------------------------------------------------------------------
  1012. /**
  1013. * @category do notation
  1014. * @since 2.9.0
  1015. */
  1016. export var Do = /*#__PURE__*/ of(_.emptyRecord);
  1017. /**
  1018. * @category do notation
  1019. * @since 2.8.0
  1020. */
  1021. export var bindTo = /*#__PURE__*/ bindTo_(Functor);
  1022. var let_ = /*#__PURE__*/ let__(Functor);
  1023. export {
  1024. /**
  1025. * @category do notation
  1026. * @since 2.13.0
  1027. */
  1028. let_ as let };
  1029. /**
  1030. * @category do notation
  1031. * @since 2.8.0
  1032. */
  1033. export var bind = /*#__PURE__*/ bind_(Chain);
  1034. /**
  1035. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  1036. *
  1037. * @category do notation
  1038. * @since 2.8.0
  1039. */
  1040. export var bindW = bind;
  1041. /**
  1042. * @category do notation
  1043. * @since 2.8.0
  1044. */
  1045. export var apS = /*#__PURE__*/ apS_(ApplyPar);
  1046. /**
  1047. * Less strict version of [`apS`](#aps).
  1048. *
  1049. * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged.
  1050. *
  1051. * @category do notation
  1052. * @since 2.8.0
  1053. */
  1054. export var apSW = apS;
  1055. /**
  1056. * @since 2.11.0
  1057. */
  1058. export var ApT = /*#__PURE__*/ of(_.emptyReadonlyArray);
  1059. // -------------------------------------------------------------------------------------
  1060. // array utils
  1061. // -------------------------------------------------------------------------------------
  1062. /**
  1063. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativePar)`.
  1064. *
  1065. * @category traversing
  1066. * @since 2.11.0
  1067. */
  1068. export var traverseReadonlyNonEmptyArrayWithIndex = function (f) {
  1069. return flow(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(TE.traverseReadonlyNonEmptyArrayWithIndex(SK)));
  1070. };
  1071. /**
  1072. * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativePar)`.
  1073. *
  1074. * @category traversing
  1075. * @since 2.11.0
  1076. */
  1077. export var traverseReadonlyArrayWithIndex = function (f) {
  1078. var g = traverseReadonlyNonEmptyArrayWithIndex(f);
  1079. return function (as) { return (_.isNonEmpty(as) ? g(as) : ApT); };
  1080. };
  1081. /**
  1082. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(ApplicativeSeq)`.
  1083. *
  1084. * @category traversing
  1085. * @since 2.11.0
  1086. */
  1087. export var traverseReadonlyNonEmptyArrayWithIndexSeq = function (f) {
  1088. return flow(R.traverseReadonlyNonEmptyArrayWithIndex(f), R.map(TE.traverseReadonlyNonEmptyArrayWithIndexSeq(SK)));
  1089. };
  1090. /**
  1091. * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
  1092. *
  1093. * @category traversing
  1094. * @since 2.11.0
  1095. */
  1096. export var traverseReadonlyArrayWithIndexSeq = function (f) {
  1097. var g = traverseReadonlyNonEmptyArrayWithIndexSeq(f);
  1098. return function (as) { return (_.isNonEmpty(as) ? g(as) : ApT); };
  1099. };
  1100. /**
  1101. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  1102. *
  1103. * @category traversing
  1104. * @since 2.9.0
  1105. */
  1106. export var traverseArrayWithIndex = traverseReadonlyArrayWithIndex;
  1107. /**
  1108. * Equivalent to `ReadonlyArray#traverse(Applicative)`.
  1109. *
  1110. * @category traversing
  1111. * @since 2.9.0
  1112. */
  1113. export var traverseArray = function (f) {
  1114. return traverseReadonlyArrayWithIndex(function (_, a) { return f(a); });
  1115. };
  1116. /**
  1117. * Equivalent to `ReadonlyArray#sequence(Applicative)`.
  1118. *
  1119. * @category traversing
  1120. * @since 2.9.0
  1121. */
  1122. export var sequenceArray = /*#__PURE__*/ traverseArray(identity);
  1123. /**
  1124. * Equivalent to `ReadonlyArray#traverseWithIndex(ApplicativeSeq)`.
  1125. *
  1126. * @category traversing
  1127. * @since 2.9.0
  1128. */
  1129. export var traverseSeqArrayWithIndex = traverseReadonlyArrayWithIndexSeq;
  1130. /**
  1131. * Equivalent to `ReadonlyArray#traverse(ApplicativeSeq)`.
  1132. *
  1133. * @category traversing
  1134. * @since 2.9.0
  1135. */
  1136. export var traverseSeqArray = function (f) {
  1137. return traverseReadonlyArrayWithIndexSeq(function (_, a) { return f(a); });
  1138. };
  1139. /**
  1140. * Equivalent to `ReadonlyArray#sequence(ApplicativeSeq)`.
  1141. *
  1142. * @category traversing
  1143. * @since 2.9.0
  1144. */
  1145. export var sequenceSeqArray = /*#__PURE__*/ traverseSeqArray(identity);
  1146. // -------------------------------------------------------------------------------------
  1147. // deprecated
  1148. // -------------------------------------------------------------------------------------
  1149. /**
  1150. * This instance is deprecated, use small, specific instances instead.
  1151. * For example if a function needs a `Functor` instance, pass `RTE.Functor` instead of `RTE.readerTaskEither`
  1152. * (where `RTE` is from `import RTE from 'fp-ts/ReaderTaskEither'`)
  1153. *
  1154. * @category zone of death
  1155. * @since 2.0.0
  1156. * @deprecated
  1157. */
  1158. export var readerTaskEither = {
  1159. URI: URI,
  1160. map: _map,
  1161. of: of,
  1162. ap: _apPar,
  1163. chain: _chain,
  1164. alt: _alt,
  1165. bimap: _bimap,
  1166. mapLeft: _mapLeft,
  1167. fromIO: fromIO,
  1168. fromTask: fromTask,
  1169. throwError: throwError
  1170. };
  1171. /**
  1172. * This instance is deprecated, use small, specific instances instead.
  1173. * For example if a function needs a `Functor` instance, pass `RTE.Functor` instead of `RTE.readerTaskEitherSeq`
  1174. * (where `RTE` is from `import RTE from 'fp-ts/ReaderTaskEither'`)
  1175. *
  1176. * @category zone of death
  1177. * @since 2.0.0
  1178. * @deprecated
  1179. */
  1180. export var readerTaskEitherSeq = {
  1181. URI: URI,
  1182. map: _map,
  1183. of: of,
  1184. ap: _apSeq,
  1185. chain: _chain,
  1186. alt: _alt,
  1187. bimap: _bimap,
  1188. mapLeft: _mapLeft,
  1189. fromIO: fromIO,
  1190. fromTask: fromTask,
  1191. throwError: throwError
  1192. };
  1193. /**
  1194. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  1195. *
  1196. * Semigroup returning the left-most `Left` value. If both operands are `Right`s then the inner values
  1197. * are concatenated using the provided `Semigroup`
  1198. *
  1199. * @category zone of death
  1200. * @since 2.0.0
  1201. * @deprecated
  1202. */
  1203. export var getApplySemigroup =
  1204. /*#__PURE__*/ getApplySemigroup_(ApplySeq);
  1205. /**
  1206. * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead.
  1207. *
  1208. * @category zone of death
  1209. * @since 2.0.0
  1210. * @deprecated
  1211. */
  1212. export var getApplyMonoid =
  1213. /*#__PURE__*/ getApplicativeMonoid(ApplicativeSeq);
  1214. /**
  1215. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  1216. *
  1217. * @category zone of death
  1218. * @since 2.0.0
  1219. * @deprecated
  1220. */
  1221. export var getSemigroup = function (S) {
  1222. return getApplySemigroup_(RT.ApplySeq)(E.getSemigroup(S));
  1223. };
  1224. /**
  1225. * Use [`getApplicativeReaderTaskValidation`](#getapplicativereadertaskvalidation) and [`getAltReaderTaskValidation`](#getaltreadertaskvalidation) instead.
  1226. *
  1227. * @category instances
  1228. * @since 2.3.0
  1229. * @deprecated
  1230. */
  1231. export function getReaderTaskValidation(SE) {
  1232. var applicativeReaderTaskValidation = getApplicativeReaderTaskValidation(T.ApplicativePar, SE);
  1233. var altReaderTaskValidation = getAltReaderTaskValidation(SE);
  1234. return {
  1235. URI: URI,
  1236. _E: undefined,
  1237. map: _map,
  1238. of: of,
  1239. chain: _chain,
  1240. bimap: _bimap,
  1241. mapLeft: _mapLeft,
  1242. ap: applicativeReaderTaskValidation.ap,
  1243. alt: altReaderTaskValidation.alt,
  1244. fromIO: fromIO,
  1245. fromTask: fromTask,
  1246. throwError: throwError
  1247. };
  1248. }
  1249. /**
  1250. * @category zone of death
  1251. * @since 2.0.0
  1252. * @deprecated
  1253. */
  1254. /* istanbul ignore next */
  1255. export function run(ma, r) {
  1256. return ma(r)();
  1257. }