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

TaskThese.d.ts 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /**
  2. * @since 2.4.0
  3. */
  4. import { Applicative2C } from './Applicative'
  5. import { Apply1, Apply2C } from './Apply'
  6. import { Bifunctor2 } from './Bifunctor'
  7. import { Chain2C } from './Chain'
  8. import { Either } from './Either'
  9. import { FromEither2 } from './FromEither'
  10. import { FromIO2 } from './FromIO'
  11. import { FromTask2 } from './FromTask'
  12. import { FromThese2 } from './FromThese'
  13. import { Lazy } from './function'
  14. import { Functor2 } from './Functor'
  15. import { IO } from './IO'
  16. import { IOEither } from './IOEither'
  17. import { Monad2C } from './Monad'
  18. import { MonadTask2C } from './MonadTask'
  19. import { Option } from './Option'
  20. import { Pointed2 } from './Pointed'
  21. import { Predicate } from './Predicate'
  22. import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
  23. import { Refinement } from './Refinement'
  24. import { Semigroup } from './Semigroup'
  25. import * as T from './Task'
  26. import * as TH from './These'
  27. import These = TH.These
  28. import Task = T.Task
  29. /**
  30. * @category model
  31. * @since 2.4.0
  32. */
  33. export interface TaskThese<E, A> extends Task<These<E, A>> {}
  34. /**
  35. * @category constructors
  36. * @since 2.4.0
  37. */
  38. export declare const left: <E = never, A = never>(e: E) => TaskThese<E, A>
  39. /**
  40. * @category constructors
  41. * @since 2.4.0
  42. */
  43. export declare const right: <E = never, A = never>(a: A) => TaskThese<E, A>
  44. /**
  45. * @category constructors
  46. * @since 2.4.0
  47. */
  48. export declare const both: <E, A>(e: E, a: A) => TaskThese<E, A>
  49. /**
  50. * @category constructors
  51. * @since 2.4.0
  52. */
  53. export declare const rightTask: <E = never, A = never>(ma: Task<A>) => TaskThese<E, A>
  54. /**
  55. * @category constructors
  56. * @since 2.4.0
  57. */
  58. export declare const leftTask: <E = never, A = never>(me: Task<E>) => TaskThese<E, A>
  59. /**
  60. * @category constructors
  61. * @since 2.4.0
  62. */
  63. export declare const rightIO: <E = never, A = never>(ma: IO<A>) => TaskThese<E, A>
  64. /**
  65. * @category constructors
  66. * @since 2.4.0
  67. */
  68. export declare const leftIO: <E = never, A = never>(me: IO<E>) => TaskThese<E, A>
  69. /**
  70. * @category conversions
  71. * @since 2.10.0
  72. */
  73. export declare const fromEither: <E, A>(fa: Either<E, A>) => TaskThese<E, A>
  74. /**
  75. * @category conversions
  76. * @since 2.11.0
  77. */
  78. export declare const fromThese: <E, A>(fa: These<E, A>) => TaskThese<E, A>
  79. /**
  80. * @category conversions
  81. * @since 2.7.0
  82. */
  83. export declare const fromIO: <A, E = never>(fa: IO<A>) => TaskThese<E, A>
  84. /**
  85. * @category conversions
  86. * @since 2.4.0
  87. */
  88. export declare const fromIOEither: <E, A>(fa: IOEither<E, A>) => TaskThese<E, A>
  89. /**
  90. * @category conversions
  91. * @since 2.7.0
  92. */
  93. export declare const fromTask: <A, E = never>(fa: Task<A>) => TaskThese<E, A>
  94. /**
  95. * @category pattern matching
  96. * @since 2.10.0
  97. */
  98. export declare const match: <E, B, A>(
  99. onLeft: (e: E) => B,
  100. onRight: (a: A) => B,
  101. onBoth: (e: E, a: A) => B
  102. ) => (fa: TaskThese<E, A>) => Task<B>
  103. /**
  104. * Less strict version of [`match`](#match).
  105. *
  106. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  107. *
  108. * @category pattern matching
  109. * @since 2.10.0
  110. */
  111. export declare const matchW: <E, B, A, C, D>(
  112. onLeft: (e: E) => B,
  113. onRight: (a: A) => C,
  114. onBoth: (e: E, a: A) => D
  115. ) => (ma: TaskThese<E, A>) => T.Task<B | C | D>
  116. /**
  117. * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`Task`).
  118. *
  119. * @category pattern matching
  120. * @since 2.10.0
  121. */
  122. export declare const matchE: <E, B, A>(
  123. onLeft: (e: E) => Task<B>,
  124. onRight: (a: A) => Task<B>,
  125. onBoth: (e: E, a: A) => Task<B>
  126. ) => (fa: TaskThese<E, A>) => Task<B>
  127. /**
  128. * Alias of [`matchE`](#matche).
  129. *
  130. * @category pattern matching
  131. * @since 2.4.0
  132. */
  133. export declare const fold: <E, B, A>(
  134. onLeft: (e: E) => T.Task<B>,
  135. onRight: (a: A) => T.Task<B>,
  136. onBoth: (e: E, a: A) => T.Task<B>
  137. ) => (fa: TaskThese<E, A>) => T.Task<B>
  138. /**
  139. * Less strict version of [`matchE`](#matche).
  140. *
  141. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  142. *
  143. * @category pattern matching
  144. * @since 2.10.0
  145. */
  146. export declare const matchEW: <E, B, A, C, D>(
  147. onLeft: (e: E) => Task<B>,
  148. onRight: (a: A) => Task<C>,
  149. onBoth: (e: E, a: A) => Task<D>
  150. ) => (fa: TaskThese<E, A>) => Task<B | C | D>
  151. /**
  152. * Alias of [`matchEW`](#matchew).
  153. *
  154. * @category pattern matching
  155. * @since 2.10.0
  156. */
  157. export declare const foldW: <E, B, A, C, D>(
  158. onLeft: (e: E) => T.Task<B>,
  159. onRight: (a: A) => T.Task<C>,
  160. onBoth: (e: E, a: A) => T.Task<D>
  161. ) => (fa: TaskThese<E, A>) => T.Task<B | C | D>
  162. /**
  163. * @since 2.4.0
  164. */
  165. export declare const swap: <E, A>(fa: TaskThese<E, A>) => TaskThese<A, E>
  166. /**
  167. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  168. * use the type constructor `F` to represent some computational context.
  169. *
  170. * @category mapping
  171. * @since 2.4.0
  172. */
  173. export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: TaskThese<E, A>) => TaskThese<E, B>
  174. /**
  175. * Map a pair of functions over the two type arguments of the bifunctor.
  176. *
  177. * @category mapping
  178. * @since 2.4.0
  179. */
  180. export declare const bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => (fa: TaskThese<E, A>) => TaskThese<G, B>
  181. /**
  182. * Map a function over the first type argument of a bifunctor.
  183. *
  184. * @category error handling
  185. * @since 2.4.0
  186. */
  187. export declare const mapLeft: <E, G>(f: (e: E) => G) => <A>(fa: TaskThese<E, A>) => TaskThese<G, A>
  188. /**
  189. * @category constructors
  190. * @since 2.7.0
  191. */
  192. export declare const of: <E = never, A = never>(a: A) => TaskThese<E, A>
  193. /**
  194. * @category type lambdas
  195. * @since 2.4.0
  196. */
  197. export declare const URI = 'TaskThese'
  198. /**
  199. * @category type lambdas
  200. * @since 2.4.0
  201. */
  202. export declare type URI = typeof URI
  203. declare module './HKT' {
  204. interface URItoKind2<E, A> {
  205. readonly [URI]: TaskThese<E, A>
  206. }
  207. }
  208. /**
  209. * @category instances
  210. * @since 2.10.0
  211. */
  212. export declare const getApply: <E>(A: Apply1<T.URI>, S: Semigroup<E>) => Apply2C<'TaskThese', E>
  213. /**
  214. * @category instances
  215. * @since 2.7.0
  216. */
  217. export declare function getApplicative<E>(A: Apply1<T.URI>, S: Semigroup<E>): Applicative2C<URI, E>
  218. /**
  219. * @category instances
  220. * @since 2.10.0
  221. */
  222. export declare function getChain<E>(S: Semigroup<E>): Chain2C<URI, E>
  223. /**
  224. * @category instances
  225. * @since 2.4.0
  226. */
  227. export declare function getMonad<E>(S: Semigroup<E>): Monad2C<URI, E> & MonadTask2C<URI, E>
  228. /**
  229. * @category instances
  230. * @since 2.10.0
  231. */
  232. export declare const Functor: Functor2<URI>
  233. /**
  234. * @category mapping
  235. * @since 2.10.0
  236. */
  237. export declare const flap: <A>(a: A) => <E, B>(fab: TaskThese<E, (a: A) => B>) => TaskThese<E, B>
  238. /**
  239. * @category instances
  240. * @since 2.10.0
  241. */
  242. export declare const Pointed: Pointed2<URI>
  243. /**
  244. * @category instances
  245. * @since 2.10.0
  246. */
  247. export declare const Bifunctor: Bifunctor2<URI>
  248. /**
  249. * @category instances
  250. * @since 2.10.0
  251. */
  252. export declare const FromEither: FromEither2<URI>
  253. /**
  254. * @category conversions
  255. * @since 2.10.0
  256. */
  257. export declare const fromOption: <E>(onNone: Lazy<E>) => <A>(fa: Option<A>) => TaskThese<E, A>
  258. /**
  259. * @category lifting
  260. * @since 2.10.0
  261. */
  262. export declare const fromOptionK: <E>(
  263. onNone: Lazy<E>
  264. ) => <A extends ReadonlyArray<unknown>, B>(f: (...a: A) => Option<B>) => (...a: A) => TaskThese<E, B>
  265. /**
  266. * @category lifting
  267. * @since 2.10.0
  268. */
  269. export declare const fromPredicate: {
  270. <A, B extends A, E>(refinement: Refinement<A, B>, onFalse: (a: A) => E): (a: A) => TaskThese<E, B>
  271. <A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): <B extends A>(b: B) => TaskThese<E, B>
  272. <A, E>(predicate: Predicate<A>, onFalse: (a: A) => E): (a: A) => TaskThese<E, A>
  273. }
  274. /**
  275. * @category instances
  276. * @since 2.11.0
  277. */
  278. export declare const FromThese: FromThese2<URI>
  279. /**
  280. * @category lifting
  281. * @since 2.11.0
  282. */
  283. export declare const fromTheseK: <A extends ReadonlyArray<unknown>, E, B>(
  284. f: (...a: A) => TH.These<E, B>
  285. ) => (...a: A) => TaskThese<E, B>
  286. /**
  287. * @category instances
  288. * @since 2.10.0
  289. */
  290. export declare const FromIO: FromIO2<URI>
  291. /**
  292. * @category lifting
  293. * @since 2.10.0
  294. */
  295. export declare const fromIOK: <A extends ReadonlyArray<unknown>, B>(
  296. f: (...a: A) => IO<B>
  297. ) => <E = never>(...a: A) => TaskThese<E, B>
  298. /**
  299. * @category instances
  300. * @since 2.10.0
  301. */
  302. export declare const FromTask: FromTask2<URI>
  303. /**
  304. * @category lifting
  305. * @since 2.10.0
  306. */
  307. export declare const fromTaskK: <A extends ReadonlyArray<unknown>, B>(
  308. f: (...a: A) => T.Task<B>
  309. ) => <E = never>(...a: A) => TaskThese<E, B>
  310. /**
  311. * @since 2.10.0
  312. */
  313. export declare const toTuple2: <E, A>(e: Lazy<E>, a: Lazy<A>) => (fa: TaskThese<E, A>) => Task<readonly [E, A]>
  314. /**
  315. * @since 2.11.0
  316. */
  317. export declare const ApT: TaskThese<never, readonly []>
  318. /**
  319. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(getApplicative(T.ApplicativePar, S))`.
  320. *
  321. * @category traversing
  322. * @since 2.11.0
  323. */
  324. export declare const traverseReadonlyNonEmptyArrayWithIndex: <E>(
  325. S: Semigroup<E>
  326. ) => <A, B>(
  327. f: (index: number, a: A) => TaskThese<E, B>
  328. ) => (as: ReadonlyNonEmptyArray<A>) => TaskThese<E, ReadonlyNonEmptyArray<B>>
  329. /**
  330. * Equivalent to `ReadonlyArray#traverseWithIndex(getApplicative(T.ApplicativePar, S))`.
  331. *
  332. * @category traversing
  333. * @since 2.11.0
  334. */
  335. export declare const traverseReadonlyArrayWithIndex: <E>(
  336. S: Semigroup<E>
  337. ) => <A, B>(f: (index: number, a: A) => TaskThese<E, B>) => (as: readonly A[]) => TaskThese<E, readonly B[]>
  338. /**
  339. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(getApplicative(T.ApplicativeSeq, S))`.
  340. *
  341. * @category traversing
  342. * @since 2.11.0
  343. */
  344. export declare const traverseReadonlyNonEmptyArrayWithIndexSeq: <E>(
  345. S: Semigroup<E>
  346. ) => <A, B>(
  347. f: (index: number, a: A) => TaskThese<E, B>
  348. ) => (as: ReadonlyNonEmptyArray<A>) => TaskThese<E, ReadonlyNonEmptyArray<B>>
  349. /**
  350. * Equivalent to `ReadonlyArray#traverseWithIndex(getApplicative(T.ApplicativeSeq, S))`.
  351. *
  352. * @category traversing
  353. * @since 2.11.0
  354. */
  355. export declare const traverseReadonlyArrayWithIndexSeq: <E>(
  356. S: Semigroup<E>
  357. ) => <A, B>(f: (index: number, a: A) => TaskThese<E, B>) => (as: readonly A[]) => TaskThese<E, readonly B[]>
  358. /**
  359. * Use [`Functor`](#functor) instead.
  360. *
  361. * @category zone of death
  362. * @since 2.7.0
  363. * @deprecated
  364. */
  365. export declare const functorTaskThese: Functor2<URI>
  366. /**
  367. * Use [`Bifunctor`](#bifunctor) instead.
  368. *
  369. * @category zone of death
  370. * @since 2.7.0
  371. * @deprecated
  372. */
  373. export declare const bifunctorTaskThese: Bifunctor2<URI>
  374. /**
  375. * Use [`toTuple2`](#totuple2) instead.
  376. *
  377. * @category zone of death
  378. * @since 2.4.0
  379. * @deprecated
  380. */
  381. export declare const toTuple: <E, A>(e: E, a: A) => (fa: TaskThese<E, A>) => T.Task<[E, A]>
  382. /**
  383. * This instance is deprecated, use small, specific instances instead.
  384. * For example if a function needs a `Functor` instance, pass `TT.Functor` instead of `TT.taskThese`
  385. * (where `TT` is from `import TT from 'fp-ts/TaskThese'`)
  386. *
  387. * @category zone of death
  388. * @since 2.4.0
  389. * @deprecated
  390. */
  391. export declare const taskThese: Functor2<URI> & Bifunctor2<URI>
  392. /**
  393. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  394. *
  395. * @category zone of death
  396. * @since 2.4.0
  397. * @deprecated
  398. */
  399. export declare const getSemigroup: <E, A>(SE: Semigroup<E>, SA: Semigroup<A>) => Semigroup<TaskThese<E, A>>