版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

260 строки
6.7 KiB

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