版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

263 wiersze
6.7 KiB

  1. /**
  2. * ```ts
  3. * interface IO<A> {
  4. * (): A
  5. * }
  6. * ```
  7. *
  8. * `IO<A>` represents a non-deterministic synchronous computation that can cause side effects, yields a value of
  9. * type `A` and **never fails**.
  10. *
  11. * If you want to represent a synchronous computation that may fail, please see `IOEither`.
  12. * If you want to represent a synchronous computation that may yield nothing, please see `IOOption`.
  13. *
  14. * @since 2.0.0
  15. */
  16. import { Applicative1 } from './Applicative'
  17. import { Apply1 } from './Apply'
  18. import { Chain1 } from './Chain'
  19. import { ChainRec1 } from './ChainRec'
  20. import { FromIO1 } from './FromIO'
  21. import { Functor1 } from './Functor'
  22. import { Monad1 } from './Monad'
  23. import { MonadIO1 } from './MonadIO'
  24. import { Monoid } from './Monoid'
  25. import { Pointed1 } from './Pointed'
  26. import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray'
  27. import { Semigroup } from './Semigroup'
  28. /**
  29. * @category model
  30. * @since 2.0.0
  31. */
  32. export interface IO<A> {
  33. (): A
  34. }
  35. /**
  36. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  37. * use the type constructor `F` to represent some computational context.
  38. *
  39. * @category mapping
  40. * @since 2.0.0
  41. */
  42. export declare const map: <A, B>(f: (a: A) => B) => (fa: IO<A>) => IO<B>
  43. /**
  44. * @since 2.0.0
  45. */
  46. export declare const ap: <A>(fa: IO<A>) => <B>(fab: IO<(a: A) => B>) => IO<B>
  47. /**
  48. * @category constructors
  49. * @since 2.0.0
  50. */
  51. export declare const of: <A>(a: A) => IO<A>
  52. /**
  53. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  54. *
  55. * @category sequencing
  56. * @since 2.0.0
  57. */
  58. export declare const chain: <A, B>(f: (a: A) => IO<B>) => (ma: IO<A>) => IO<B>
  59. /**
  60. * @category sequencing
  61. * @since 2.0.0
  62. */
  63. export declare const flatten: <A>(mma: IO<IO<A>>) => IO<A>
  64. /**
  65. * @category type lambdas
  66. * @since 2.0.0
  67. */
  68. export declare const URI = 'IO'
  69. /**
  70. * @category type lambdas
  71. * @since 2.0.0
  72. */
  73. export declare type URI = typeof URI
  74. declare module './HKT' {
  75. interface URItoKind<A> {
  76. readonly [URI]: IO<A>
  77. }
  78. }
  79. /**
  80. * @category instances
  81. * @since 2.7.0
  82. */
  83. export declare const Functor: Functor1<URI>
  84. /**
  85. * @category mapping
  86. * @since 2.10.0
  87. */
  88. export declare const flap: <A>(a: A) => <B>(fab: IO<(a: A) => B>) => IO<B>
  89. /**
  90. * @category instances
  91. * @since 2.10.0
  92. */
  93. export declare const Pointed: Pointed1<URI>
  94. /**
  95. * @category instances
  96. * @since 2.10.0
  97. */
  98. export declare const Apply: Apply1<URI>
  99. /**
  100. * Combine two effectful actions, keeping only the result of the first.
  101. *
  102. * @since 2.0.0
  103. */
  104. export declare const apFirst: <B>(second: IO<B>) => <A>(first: IO<A>) => IO<A>
  105. /**
  106. * Combine two effectful actions, keeping only the result of the second.
  107. *
  108. * @since 2.0.0
  109. */
  110. export declare const apSecond: <B>(second: IO<B>) => <A>(first: IO<A>) => IO<B>
  111. /**
  112. * @category instances
  113. * @since 2.7.0
  114. */
  115. export declare const Applicative: Applicative1<URI>
  116. /**
  117. * @category instances
  118. * @since 2.10.0
  119. */
  120. export declare const Chain: Chain1<URI>
  121. /**
  122. * @category instances
  123. * @since 2.7.0
  124. */
  125. export declare const Monad: Monad1<URI>
  126. /**
  127. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  128. * keeping only the result of the first.
  129. *
  130. * @category sequencing
  131. * @since 2.0.0
  132. */
  133. export declare const chainFirst: <A, B>(f: (a: A) => IO<B>) => (first: IO<A>) => IO<A>
  134. /**
  135. * @category zone of death
  136. * @since 2.7.0
  137. * @deprecated
  138. */
  139. export declare const fromIO: <A>(fa: IO<A>) => IO<A>
  140. /**
  141. * @category instances
  142. * @since 2.7.0
  143. */
  144. export declare const MonadIO: MonadIO1<URI>
  145. /**
  146. * @category instances
  147. * @since 2.7.0
  148. */
  149. export declare const ChainRec: ChainRec1<URI>
  150. /**
  151. * @category instances
  152. * @since 2.10.0
  153. */
  154. export declare const FromIO: FromIO1<URI>
  155. /**
  156. * @category do notation
  157. * @since 2.9.0
  158. */
  159. export declare const Do: IO<{}>
  160. /**
  161. * @category do notation
  162. * @since 2.8.0
  163. */
  164. export declare const bindTo: <N extends string>(name: N) => <A>(fa: IO<A>) => IO<{ readonly [K in N]: A }>
  165. declare const let_: <N extends string, A, B>(
  166. name: Exclude<N, keyof A>,
  167. f: (a: A) => B
  168. ) => (fa: IO<A>) => IO<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  169. export {
  170. /**
  171. * @category do notation
  172. * @since 2.13.0
  173. */
  174. let_ as let
  175. }
  176. /**
  177. * @category do notation
  178. * @since 2.8.0
  179. */
  180. export declare const bind: <N extends string, A, B>(
  181. name: Exclude<N, keyof A>,
  182. f: (a: A) => IO<B>
  183. ) => (ma: IO<A>) => IO<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  184. /**
  185. * @category do notation
  186. * @since 2.8.0
  187. */
  188. export declare const apS: <N extends string, A, B>(
  189. name: Exclude<N, keyof A>,
  190. fb: IO<B>
  191. ) => (fa: IO<A>) => IO<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
  192. /**
  193. * @since 2.11.0
  194. */
  195. export declare const ApT: IO<readonly []>
  196. /**
  197. * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.
  198. *
  199. * @category traversing
  200. * @since 2.11.0
  201. */
  202. export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, B>(
  203. f: (index: number, a: A) => IO<B>
  204. ) => (as: ReadonlyNonEmptyArray<A>) => IO<ReadonlyNonEmptyArray<B>>
  205. /**
  206. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  207. *
  208. * @category traversing
  209. * @since 2.11.0
  210. */
  211. export declare const traverseReadonlyArrayWithIndex: <A, B>(
  212. f: (index: number, a: A) => IO<B>
  213. ) => (as: readonly A[]) => IO<readonly B[]>
  214. /**
  215. * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.
  216. *
  217. * @category traversing
  218. * @since 2.9.0
  219. */
  220. export declare const traverseArrayWithIndex: <A, B>(
  221. f: (index: number, a: A) => IO<B>
  222. ) => (as: ReadonlyArray<A>) => IO<ReadonlyArray<B>>
  223. /**
  224. * Equivalent to `ReadonlyArray#traverse(Applicative)`.
  225. *
  226. * @category traversing
  227. * @since 2.9.0
  228. */
  229. export declare const traverseArray: <A, B>(f: (a: A) => IO<B>) => (as: readonly A[]) => IO<readonly B[]>
  230. /**
  231. * Equivalent to `ReadonlyArray#sequence(Applicative)`.
  232. *
  233. * @category traversing
  234. * @since 2.9.0
  235. */
  236. export declare const sequenceArray: <A>(arr: ReadonlyArray<IO<A>>) => IO<ReadonlyArray<A>>
  237. /**
  238. * This instance is deprecated, use small, specific instances instead.
  239. * For example if a function needs a `Functor` instance, pass `IO.Functor` instead of `IO.io`
  240. * (where `IO` is from `import IO from 'fp-ts/IO'`)
  241. *
  242. * @category zone of death
  243. * @since 2.0.0
  244. * @deprecated
  245. */
  246. export declare const io: Monad1<URI> & MonadIO1<URI> & ChainRec1<URI>
  247. /**
  248. * Use [`getApplySemigroup`](./Apply.ts.html#getapplysemigroup) instead.
  249. *
  250. * @category zone of death
  251. * @since 2.0.0
  252. * @deprecated
  253. */
  254. export declare const getSemigroup: <A>(S: Semigroup<A>) => Semigroup<IO<A>>
  255. /**
  256. * Use [`getApplicativeMonoid`](./Applicative.ts.html#getapplicativemonoid) instead.
  257. *
  258. * @category zone of death
  259. * @since 2.0.0
  260. * @deprecated
  261. */
  262. export declare const getMonoid: <A>(M: Monoid<A>) => Monoid<IO<A>>