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

Writer.d.ts 3.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @since 2.0.0
  3. */
  4. import { Applicative2C } from './Applicative'
  5. import { Apply2C } from './Apply'
  6. import { Chain2C } from './Chain'
  7. import { Functor2 } from './Functor'
  8. import { Monad2C } from './Monad'
  9. import { Monoid } from './Monoid'
  10. import { Pointed2C } from './Pointed'
  11. import { Semigroup } from './Semigroup'
  12. /**
  13. * @category model
  14. * @since 2.0.0
  15. */
  16. export interface Writer<W, A> {
  17. (): [A, W]
  18. }
  19. /**
  20. * Appends a value to the accumulator
  21. *
  22. * @category constructors
  23. * @since 2.0.0
  24. */
  25. export declare const tell: <W>(w: W) => Writer<W, void>
  26. /**
  27. * Modifies the result to include the changes to the accumulator
  28. *
  29. * @since 2.0.0
  30. */
  31. export declare const listen: <W, A>(fa: Writer<W, A>) => Writer<W, [A, W]>
  32. /**
  33. * Applies the returned function to the accumulator
  34. *
  35. * @since 2.0.0
  36. */
  37. export declare const pass: <W, A>(fa: Writer<W, [A, (w: W) => W]>) => Writer<W, A>
  38. /**
  39. * Projects a value from modifications made to the accumulator during an action
  40. *
  41. * @since 2.0.0
  42. */
  43. export declare const listens: <W, B>(f: (w: W) => B) => <A>(fa: Writer<W, A>) => Writer<W, [A, B]>
  44. /**
  45. * Modify the final accumulator value by applying a function
  46. *
  47. * @since 2.0.0
  48. */
  49. export declare const censor: <W>(f: (w: W) => W) => <A>(fa: Writer<W, A>) => Writer<W, A>
  50. /**
  51. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  52. * use the type constructor `F` to represent some computational context.
  53. *
  54. * @category mapping
  55. * @since 2.0.0
  56. */
  57. export declare const map: <A, B>(f: (a: A) => B) => <E>(fa: Writer<E, A>) => Writer<E, B>
  58. /**
  59. * @category type lambdas
  60. * @since 2.0.0
  61. */
  62. export declare const URI = 'Writer'
  63. /**
  64. * @category type lambdas
  65. * @since 2.0.0
  66. */
  67. export declare type URI = typeof URI
  68. declare module './HKT' {
  69. interface URItoKind2<E, A> {
  70. readonly [URI]: Writer<E, A>
  71. }
  72. }
  73. /**
  74. * @category instances
  75. * @since 2.10.0
  76. */
  77. export declare const getPointed: <W>(M: Monoid<W>) => Pointed2C<'Writer', W>
  78. /**
  79. * @category instances
  80. * @since 2.10.0
  81. */
  82. export declare const getApply: <W>(S: Semigroup<W>) => Apply2C<'Writer', W>
  83. /**
  84. * @category instances
  85. * @since 2.10.0
  86. */
  87. export declare const getApplicative: <W>(M: Monoid<W>) => Applicative2C<'Writer', W>
  88. /**
  89. * @category instances
  90. * @since 2.10.0
  91. */
  92. export declare function getChain<W>(S: Semigroup<W>): Chain2C<URI, W>
  93. /**
  94. * @category instances
  95. * @since 2.0.0
  96. */
  97. export declare function getMonad<W>(M: Monoid<W>): Monad2C<URI, W>
  98. /**
  99. * @category instances
  100. * @since 2.7.0
  101. */
  102. export declare const Functor: Functor2<URI>
  103. /**
  104. * @category mapping
  105. * @since 2.10.0
  106. */
  107. export declare const flap: <A>(a: A) => <E, B>(fab: Writer<E, (a: A) => B>) => Writer<E, B>
  108. /**
  109. * @since 2.8.0
  110. */
  111. export declare const evaluate: <W, A>(fa: Writer<W, A>) => A
  112. /**
  113. * @since 2.8.0
  114. */
  115. export declare const execute: <W, A>(fa: Writer<W, A>) => W
  116. /**
  117. * Use [`evaluate`](#evaluate) instead
  118. *
  119. * @category zone of death
  120. * @since 2.0.0
  121. * @deprecated
  122. */
  123. export declare const evalWriter: <W, A>(fa: Writer<W, A>) => A
  124. /**
  125. * Use [`execute`](#execute) instead
  126. *
  127. * @category zone of death
  128. * @since 2.0.0
  129. * @deprecated
  130. */
  131. export declare const execWriter: <W, A>(fa: Writer<W, A>) => W
  132. /**
  133. * Use [`Functor`](#functor) instead.
  134. *
  135. * @category zone of death
  136. * @since 2.0.0
  137. * @deprecated
  138. */
  139. export declare const writer: Functor2<URI>