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

390 lines
11 KiB

  1. /**
  2. * @since 2.13.0
  3. */
  4. import { Applicative2 } from './Applicative'
  5. import { Apply2 } from './Apply'
  6. import { Chain2 } from './Chain'
  7. import { FromIO2 } from './FromIO'
  8. import { FromReader2 } from './FromReader'
  9. import { Functor2 } from './Functor'
  10. import * as I from './IO'
  11. import { Monad2 } from './Monad'
  12. import { MonadIO2 } from './MonadIO'
  13. import { Pointed2 } from './Pointed'
  14. import * as R from './Reader'
  15. import { Reader } from './Reader'
  16. import { IO } from './IO'
  17. import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
  18. /**
  19. * @category model
  20. * @since 2.13.0
  21. */
  22. export interface ReaderIO<R, A> {
  23. (r: R): I.IO<A>
  24. }
  25. /**
  26. * @category conversions
  27. * @since 2.13.0
  28. */
  29. export declare const fromReader: <R, A>(fa: Reader<R, A>) => ReaderIO<R, A>
  30. /**
  31. * @category conversions
  32. * @since 2.13.0
  33. */
  34. export declare const fromIO: <A, R = unknown>(fa: IO<A>) => ReaderIO<R, A>
  35. /**
  36. * Changes the value of the local context during the execution of the action `ma` (similar to `Contravariant`'s
  37. * `contramap`).
  38. *
  39. * @since 2.13.0
  40. */
  41. export declare const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
  42. /**
  43. * Less strict version of [`asksReaderIO`](#asksreaderio).
  44. *
  45. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  46. *
  47. * @category constructors
  48. * @since 2.13.0
  49. */
  50. export declare const asksReaderIOW: <R1, R2, A>(f: (r1: R1) => ReaderIO<R2, A>) => ReaderIO<R1 & R2, A>
  51. /**
  52. * Effectfully accesses the environment.
  53. *
  54. * @category constructors
  55. * @since 2.13.0
  56. */
  57. export declare const asksReaderIO: <R, A>(f: (r: R) => ReaderIO<R, A>) => ReaderIO<R, A>
  58. /**
  59. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  60. * use the type constructor `F` to represent some computational context.
  61. *
  62. * @category mapping
  63. * @since 2.13.0
  64. */
  65. export declare const map: <A, B>(f: (a: A) => B) => <R>(fa: ReaderIO<R, A>) => ReaderIO<R, B>
  66. /**
  67. * @since 2.13.0
  68. */
  69. export declare const ap: <R, A>(fa: ReaderIO<R, A>) => <B>(fab: ReaderIO<R, (a: A) => B>) => ReaderIO<R, B>
  70. /**
  71. * Less strict version of [`ap`](#ap).
  72. *
  73. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  74. *
  75. * @since 2.13.0
  76. */
  77. export declare const apW: <R2, A>(
  78. fa: ReaderIO<R2, A>
  79. ) => <R1, B>(fab: ReaderIO<R1, (a: A) => B>) => ReaderIO<R1 & R2, B>
  80. /**
  81. * @category constructors
  82. * @since 2.13.0
  83. */
  84. export declare const of: <R = unknown, A = never>(a: A) => ReaderIO<R, A>
  85. /**
  86. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  87. *
  88. * @category sequencing
  89. * @since 2.13.0
  90. */
  91. export declare const chain: <A, R, B>(f: (a: A) => ReaderIO<R, B>) => (ma: ReaderIO<R, A>) => ReaderIO<R, B>
  92. /**
  93. * Less strict version of [`chain`](#chain).
  94. *
  95. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  96. *
  97. * @category sequencing
  98. * @since 2.13.0
  99. */
  100. export declare const chainW: <A, R2, B>(
  101. f: (a: A) => ReaderIO<R2, B>
  102. ) => <R1>(ma: ReaderIO<R1, A>) => ReaderIO<R1 & R2, B>
  103. /**
  104. * Less strict version of [`flatten`](#flatten).
  105. *
  106. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  107. *
  108. * @category sequencing
  109. * @since 2.13.0
  110. */
  111. export declare const flattenW: <R1, R2, A>(mma: ReaderIO<R1, ReaderIO<R2, A>>) => ReaderIO<R1 & R2, A>
  112. /**
  113. * @category sequencing
  114. * @since 2.13.0
  115. */
  116. export declare const flatten: <R, A>(mma: ReaderIO<R, ReaderIO<R, A>>) => ReaderIO<R, A>
  117. /**
  118. * @category type lambdas
  119. * @since 2.13.0
  120. */
  121. export declare const URI = 'ReaderIO'
  122. /**
  123. * @category type lambdas
  124. * @since 2.13.0
  125. */
  126. export declare type URI = typeof URI
  127. declare module './HKT' {
  128. interface URItoKind2<E, A> {
  129. readonly [URI]: ReaderIO<E, A>
  130. }
  131. }
  132. /**
  133. * @category instances
  134. * @since 2.13.0
  135. */
  136. export declare const Functor: Functor2<URI>
  137. /**
  138. * @category mapping
  139. * @since 2.13.0
  140. */
  141. export declare const flap: <A>(a: A) => <E, B>(fab: ReaderIO<E, (a: A) => B>) => ReaderIO<E, B>
  142. /**
  143. * @category instances
  144. * @since 2.13.0
  145. */
  146. export declare const Pointed: Pointed2<URI>
  147. /**
  148. * @category instances
  149. * @since 2.13.0
  150. */
  151. export declare const Apply: Apply2<URI>
  152. /**
  153. * Combine two effectful actions, keeping only the result of the first.
  154. *
  155. * @since 2.13.0
  156. */
  157. export declare const apFirst: <E, B>(second: ReaderIO<E, B>) => <A>(first: ReaderIO<E, A>) => ReaderIO<E, A>
  158. /**
  159. * Combine two effectful actions, keeping only the result of the second.
  160. *
  161. * @since 2.13.0
  162. */
  163. export declare const apSecond: <E, B>(second: ReaderIO<E, B>) => <A>(first: ReaderIO<E, A>) => ReaderIO<E, B>
  164. /**
  165. * @category instances
  166. * @since 2.13.0
  167. */
  168. export declare const Applicative: Applicative2<URI>
  169. /**
  170. * @category instances
  171. * @since 2.13.0
  172. */
  173. export declare const Chain: Chain2<URI>
  174. /**
  175. * @category instances
  176. * @since 2.13.0
  177. */
  178. export declare const Monad: Monad2<URI>
  179. /**
  180. * @category instances
  181. * @since 2.13.0
  182. */
  183. export declare const MonadIO: MonadIO2<URI>
  184. /**
  185. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  186. * keeping only the result of the first.
  187. *
  188. * @category sequencing
  189. * @since 2.13.0
  190. */
  191. export declare const chainFirst: <A, R, B>(f: (a: A) => ReaderIO<R, B>) => (first: ReaderIO<R, A>) => ReaderIO<R, A>
  192. /**
  193. * Less strict version of [`chainFirst`](#chainfirst).
  194. *
  195. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  196. *
  197. * @category sequencing
  198. * @since 2.13.0
  199. */
  200. export declare const chainFirstW: <A, R2, B>(
  201. f: (a: A) => ReaderIO<R2, B>
  202. ) => <R1>(ma: ReaderIO<R1, A>) => ReaderIO<R1 & R2, A>
  203. /**
  204. * @category instances
  205. * @since 2.13.0
  206. */
  207. export declare const FromIO: FromIO2<URI>
  208. /**
  209. * @category lifting
  210. * @since 2.13.0
  211. */
  212. export declare const fromIOK: <A extends ReadonlyArray<unknown>, B>(
  213. f: (...a: A) => I.IO<B>
  214. ) => <R = unknown>(...a: A) => ReaderIO<R, B>
  215. /**
  216. * @category sequencing
  217. * @since 2.13.0
  218. */
  219. export declare const chainIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: ReaderIO<E, A>) => ReaderIO<E, B>
  220. /**
  221. * @category sequencing
  222. * @since 2.13.0
  223. */
  224. export declare const chainFirstIOK: <A, B>(f: (a: A) => I.IO<B>) => <E>(first: ReaderIO<E, A>) => ReaderIO<E, A>
  225. /**
  226. * @category instances
  227. * @since 2.13.0
  228. */
  229. export declare const FromReader: FromReader2<URI>
  230. /**
  231. * Reads the current context.
  232. *
  233. * @category constructors
  234. * @since 2.13.0
  235. */
  236. export declare const ask: <R>() => ReaderIO<R, R>
  237. /**
  238. * Projects a value from the global context in a `ReaderIO`.
  239. *
  240. * @category constructors
  241. * @since 2.13.0
  242. */
  243. export declare const asks: <R, A>(f: (r: R) => A) => ReaderIO<R, A>
  244. /**
  245. * @category lifting
  246. * @since 2.13.0
  247. */
  248. export declare const fromReaderK: <A extends ReadonlyArray<unknown>, R, B>(
  249. f: (...a: A) => R.Reader<R, B>
  250. ) => (...a: A) => ReaderIO<R, B>
  251. /**
  252. * @category sequencing
  253. * @since 2.13.0
  254. */
  255. export declare const chainReaderK: <A, R, B>(f: (a: A) => R.Reader<R, B>) => (ma: ReaderIO<R, A>) => ReaderIO<R, B>
  256. /**
  257. * Less strict version of [`chainReaderK`](#chainreaderk).
  258. *
  259. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  260. *
  261. * @category sequencing
  262. * @since 2.13.0
  263. */
  264. export declare const chainReaderKW: <A, R1, B>(
  265. f: (a: A) => R.Reader<R1, B>
  266. ) => <R2>(ma: ReaderIO<R2, A>) => ReaderIO<R1 & R2, B>
  267. /**
  268. * @category sequencing
  269. * @since 2.13.0
  270. */
  271. export declare const chainFirstReaderK: <A, R, B>(f: (a: A) => R.Reader<R, B>) => (ma: ReaderIO<R, A>) => ReaderIO<R, A>
  272. /**
  273. * Less strict version of [`chainFirstReaderK`](#chainfirstreaderk).
  274. *
  275. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  276. *
  277. * @category sequencing
  278. * @since 2.13.0
  279. */
  280. export declare const chainFirstReaderKW: <A, R1, B>(
  281. f: (a: A) => R.Reader<R1, B>
  282. ) => <R2>(ma: ReaderIO<R2, A>) => ReaderIO<R1 & R2, A>
  283. /**
  284. * @category do notation
  285. * @since 2.13.0
  286. */
  287. export declare const Do: ReaderIO<unknown, {}>
  288. /**
  289. * @category do notation
  290. * @since 2.13.0
  291. */
  292. export declare const bindTo: <N extends string>(
  293. name: N
  294. ) => <E, A>(fa: ReaderIO<E, A>) => ReaderIO<E, { readonly [K in N]: A }>
  295. /**
  296. * @category do notation
  297. * @since 2.13.0
  298. */
  299. export declare const bind: <N extends string, A, E, B>(
  300. name: Exclude<N, keyof A>,
  301. f: (a: A) => ReaderIO<E, B>
  302. ) => (ma: ReaderIO<E, A>) => ReaderIO<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  303. /**
  304. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  305. *
  306. * @category do notation
  307. * @since 2.13.0
  308. */
  309. export declare const bindW: <N extends string, A, R2, B>(
  310. name: Exclude<N, keyof A>,
  311. f: (a: A) => ReaderIO<R2, B>
  312. ) => <R1>(fa: ReaderIO<R1, A>) => ReaderIO<
  313. R1 & R2,
  314. {
  315. readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
  316. }
  317. >
  318. /**
  319. * @category do notation
  320. * @since 2.13.0
  321. */
  322. export declare const apS: <N extends string, A, E, B>(
  323. name: Exclude<N, keyof A>,
  324. fb: ReaderIO<E, B>
  325. ) => (fa: ReaderIO<E, A>) => ReaderIO<E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  326. /**
  327. * Less strict version of [`apS`](#aps).
  328. *
  329. * The `W` suffix (short for **W**idening) means that the environment types will be merged.
  330. *
  331. * @category do notation
  332. * @since 2.13.0
  333. */
  334. export declare const apSW: <N extends string, A, R2, B>(
  335. name: Exclude<N, keyof A>,
  336. fb: ReaderIO<R2, B>
  337. ) => <R1>(fa: ReaderIO<R1, A>) => ReaderIO<
  338. R1 & R2,
  339. {
  340. readonly [K in keyof A | N]: K extends keyof A ? A[K] : B
  341. }
  342. >
  343. /**
  344. * @since 2.13.0
  345. */
  346. export declare const ApT: ReaderIO<unknown, readonly []>
  347. /**
  348. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  349. *
  350. * @category traversing
  351. * @since 2.13.0
  352. */
  353. export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, R, B>(
  354. f: (index: number, a: A) => ReaderIO<R, B>
  355. ) => (as: ReadonlyNonEmptyArray<A>) => ReaderIO<R, ReadonlyNonEmptyArray<B>>
  356. /**
  357. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  358. *
  359. * @category traversing
  360. * @since 2.13.0
  361. */
  362. export declare const traverseReadonlyArrayWithIndex: <A, R, B>(
  363. f: (index: number, a: A) => ReaderIO<R, B>
  364. ) => (as: readonly A[]) => ReaderIO<R, readonly B[]>
  365. /**
  366. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  367. *
  368. * @category traversing
  369. * @since 2.13.0
  370. */
  371. export declare const traverseArrayWithIndex: <A, R, B>(
  372. f: (index: number, a: A) => ReaderIO<R, B>
  373. ) => (as: ReadonlyArray<A>) => ReaderIO<R, ReadonlyArray<B>>
  374. /**
  375. * Equivalent to `ReadonlyArray#traverse(Applicative)`.
  376. *
  377. * @category traversing
  378. * @since 2.13.0
  379. */
  380. export declare const traverseArray: <A, R, B>(
  381. f: (a: A) => ReaderIO<R, B>
  382. ) => (as: readonly A[]) => ReaderIO<R, readonly B[]>
  383. /**
  384. * Equivalent to `ReadonlyArray#sequence(Applicative)`.
  385. *
  386. * @category traversing
  387. * @since 2.13.0
  388. */
  389. export declare const sequenceArray: <R, A>(arr: ReadonlyArray<ReaderIO<R, A>>) => ReaderIO<R, ReadonlyArray<A>>