版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

Strong.d.ts 6.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * The `Strong` class extends `Profunctor` with combinators for working with product types.
  3. *
  4. * `first` and `second` lift values in a `Profunctor` to act on the first and second components of a tuple,
  5. * respectively.
  6. *
  7. * Another way to think about Strong is to piggyback on the intuition of
  8. * inputs and outputs. Rewriting the type signature in this light then yields:
  9. *
  10. * ```purescript
  11. * first :: forall input output a. p input output -> p (Tuple input a) (Tuple output a)
  12. * second :: forall input output a. p input output -> p (Tuple a input) (Tuple a output)
  13. * ```
  14. *
  15. * If we specialize the profunctor p to the function arrow, we get the following type
  16. * signatures, which may look a bit more familiar:
  17. *
  18. * ```purescript
  19. * first :: forall input output a. (input -> output) -> (Tuple input a) -> (Tuple output a)
  20. * second :: forall input output a. (input -> output) -> (Tuple a input) -> (Tuple a output)
  21. * ```
  22. *
  23. * So, when the `profunctor` is `Function` application, `first` essentially applies your function
  24. * to the first element of a tuple, and `second` applies it to the second element (same as `map` would do).
  25. *
  26. * Adapted from https://github.com/purescript/purescript-profunctor/blob/master/src/Data/Profunctor/Strong.purs
  27. *
  28. * @since 2.0.0
  29. */
  30. import { Category, Category2, Category3, Category4 } from './Category'
  31. import { HKT2, Kind2, Kind3, URIS2, URIS3, URIS4, Kind4 } from './HKT'
  32. import { Profunctor, Profunctor2, Profunctor3, Profunctor4 } from './Profunctor'
  33. /**
  34. * @category model
  35. * @since 2.0.0
  36. */
  37. export interface Strong<F> extends Profunctor<F> {
  38. readonly first: <A, B, C>(pab: HKT2<F, A, B>) => HKT2<F, [A, C], [B, C]>
  39. readonly second: <A, B, C>(pab: HKT2<F, B, C>) => HKT2<F, [A, B], [A, C]>
  40. }
  41. /**
  42. * @category model
  43. * @since 2.0.0
  44. */
  45. export interface Strong2<F extends URIS2> extends Profunctor2<F> {
  46. readonly first: <A, B, C>(pab: Kind2<F, A, B>) => Kind2<F, [A, C], [B, C]>
  47. readonly second: <A, B, C>(pab: Kind2<F, B, C>) => Kind2<F, [A, B], [A, C]>
  48. }
  49. /**
  50. * @category model
  51. * @since 2.0.0
  52. */
  53. export interface Strong3<F extends URIS3> extends Profunctor3<F> {
  54. readonly first: <R, A, B, C>(pab: Kind3<F, R, A, B>) => Kind3<F, R, [A, C], [B, C]>
  55. readonly second: <R, A, B, C>(pab: Kind3<F, R, B, C>) => Kind3<F, R, [A, B], [A, C]>
  56. }
  57. /**
  58. * @category model
  59. * @since 2.0.0
  60. */
  61. export interface Strong4<F extends URIS4> extends Profunctor4<F> {
  62. readonly first: <S, R, A, B, C>(pab: Kind4<F, S, R, A, B>) => Kind4<F, S, R, [A, C], [B, C]>
  63. readonly second: <S, R, A, B, C>(pab: Kind4<F, S, R, B, C>) => Kind4<F, S, R, [A, B], [A, C]>
  64. }
  65. /**
  66. * Compose a value acting on a tuple from two values, each acting on one of the components of the tuple.
  67. *
  68. * Specializing `split` to function application would look like this:
  69. *
  70. * ```purescript
  71. * split :: forall a b c d. (a -> b) -> (c -> d) -> (Tuple a c) -> (Tuple b d)
  72. * ```
  73. *
  74. * We take two functions, `f` and `g`, and we transform them into a single function which takes a tuple and maps `f`
  75. * over the first element and `g` over the second. Just like `bi-map` would do for the `bi-functor` instance of tuple.
  76. *
  77. * @since 2.10.0
  78. */
  79. export declare function split<F extends URIS4>(
  80. S: Strong4<F>,
  81. C: Category4<F>
  82. ): <S, R, A, B, C, D>(pab: Kind4<F, S, R, A, B>, pcd: Kind4<F, S, R, C, D>) => Kind4<F, S, R, [A, C], [B, D]>
  83. export declare function split<F extends URIS3>(
  84. S: Strong3<F>,
  85. C: Category3<F>
  86. ): <R, A, B, C, D>(pab: Kind3<F, R, A, B>, pcd: Kind3<F, R, C, D>) => Kind3<F, R, [A, C], [B, D]>
  87. export declare function split<F extends URIS2>(
  88. S: Strong2<F>,
  89. C: Category2<F>
  90. ): <A, B, C, D>(pab: Kind2<F, A, B>, pcd: Kind2<F, C, D>) => Kind2<F, [A, C], [B, D]>
  91. export declare function split<F>(
  92. S: Strong<F>,
  93. C: Category<F>
  94. ): <A, B, C, D>(pab: HKT2<F, A, B>, pcd: HKT2<F, C, D>) => HKT2<F, [A, C], [B, D]>
  95. /**
  96. * Compose a value which introduces a tuple from two values, each introducing one side of the tuple.
  97. *
  98. * This combinator is useful when assembling values from smaller components, because it provides a way to support two
  99. * different types of output.
  100. *
  101. * Specializing `fanOut` to function application would look like this:
  102. *
  103. * ```purescript
  104. * fanOut :: forall a b c. (a -> b) -> (a -> c) -> (a -> (Tuple b c))
  105. * ```
  106. *
  107. * We take two functions, `f` and `g`, with the same parameter type and we transform them into a single function which
  108. * takes one parameter and returns a tuple of the results of running `f` and `g` on the parameter, respectively. This
  109. * allows us to run two parallel computations on the same input and return both results in a tuple.
  110. *
  111. * @since 2.10.0
  112. */
  113. export declare function fanOut<F extends URIS4>(
  114. S: Strong4<F>,
  115. C: Category4<F>
  116. ): <S, R, A, B, C>(pab: Kind4<F, S, R, A, B>, pac: Kind4<F, S, R, A, C>) => Kind4<F, S, R, A, [B, C]>
  117. export declare function fanOut<F extends URIS3>(
  118. S: Strong3<F>,
  119. C: Category3<F>
  120. ): <R, A, B, C>(pab: Kind3<F, R, A, B>, pac: Kind3<F, R, A, C>) => Kind3<F, R, A, [B, C]>
  121. export declare function fanOut<F extends URIS2>(
  122. S: Strong2<F>,
  123. C: Category2<F>
  124. ): <A, B, C>(pab: Kind2<F, A, B>, pac: Kind2<F, A, C>) => Kind2<F, A, [B, C]>
  125. export declare function fanOut<F>(
  126. S: Strong<F>,
  127. C: Category<F>
  128. ): <A, B, C>(pab: HKT2<F, A, B>, pac: HKT2<F, A, C>) => HKT2<F, A, [B, C]>
  129. /**
  130. * Use [`split`](#split) instead.
  131. *
  132. * @category zone of death
  133. * @since 2.0.0
  134. * @deprecated
  135. */
  136. export declare function splitStrong<F extends URIS4>(
  137. F: Category4<F> & Strong4<F>
  138. ): <S, R, A, B, C, D>(pab: Kind4<F, S, R, A, B>, pcd: Kind4<F, S, R, C, D>) => Kind4<F, S, R, [A, C], [B, D]>
  139. /** @deprecated */
  140. export declare function splitStrong<F extends URIS3>(
  141. F: Category3<F> & Strong3<F>
  142. ): <R, A, B, C, D>(pab: Kind3<F, R, A, B>, pcd: Kind3<F, R, C, D>) => Kind3<F, R, [A, C], [B, D]>
  143. /** @deprecated */
  144. export declare function splitStrong<F extends URIS2>(
  145. F: Category2<F> & Strong2<F>
  146. ): <A, B, C, D>(pab: Kind2<F, A, B>, pcd: Kind2<F, C, D>) => Kind2<F, [A, C], [B, D]>
  147. /** @deprecated */
  148. export declare function splitStrong<F>(
  149. F: Category<F> & Strong<F>
  150. ): <A, B, C, D>(pab: HKT2<F, A, B>, pcd: HKT2<F, C, D>) => HKT2<F, [A, C], [B, D]>
  151. /**
  152. * Use [`fanOut`](#fanout) instead.
  153. *
  154. * @category zone of death
  155. * @since 2.0.0
  156. * @deprecated
  157. */
  158. export declare function fanout<F extends URIS4>(
  159. F: Category4<F> & Strong4<F>
  160. ): <S, R, A, B, C>(pab: Kind4<F, S, R, A, B>, pac: Kind4<F, S, R, A, C>) => Kind4<F, S, R, A, [B, C]>
  161. /** @deprecated */
  162. export declare function fanout<F extends URIS3>(
  163. F: Category3<F> & Strong3<F>
  164. ): <R, A, B, C>(pab: Kind3<F, R, A, B>, pac: Kind3<F, R, A, C>) => Kind3<F, R, A, [B, C]>
  165. /** @deprecated */
  166. export declare function fanout<F extends URIS2>(
  167. F: Category2<F> & Strong2<F>
  168. ): <A, B, C>(pab: Kind2<F, A, B>, pac: Kind2<F, A, C>) => Kind2<F, A, [B, C]>
  169. /** @deprecated */
  170. export declare function fanout<F>(
  171. F: Category<F> & Strong<F>
  172. ): <A, B, C>(pab: HKT2<F, A, B>, pac: HKT2<F, A, C>) => HKT2<F, A, [B, C]>