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

IOEither.d.ts 24 KiB

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