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

177 wiersze
3.7 KiB

  1. import { identity, pipe, unsafeCoerce } from './function';
  2. import { flap as flap_ } from './Functor';
  3. /**
  4. * @category constructors
  5. * @since 2.0.0
  6. */
  7. export var make = unsafeCoerce;
  8. /**
  9. * @category instances
  10. * @since 2.0.0
  11. */
  12. export function getShow(S) {
  13. return {
  14. show: function (c) { return "make(".concat(S.show(c), ")"); }
  15. };
  16. }
  17. /**
  18. * @category instances
  19. * @since 2.0.0
  20. */
  21. export var getEq = identity;
  22. /**
  23. * @category instances
  24. * @since 2.6.0
  25. */
  26. export var getOrd = identity;
  27. /**
  28. * @category instances
  29. * @since 2.6.0
  30. */
  31. export var getBounded = identity;
  32. /**
  33. * @category instances
  34. * @since 2.6.0
  35. */
  36. export var getSemigroup = identity;
  37. /**
  38. * @category instances
  39. * @since 2.6.0
  40. */
  41. export var getMonoid = identity;
  42. /**
  43. * @category instances
  44. * @since 2.6.0
  45. */
  46. export var getSemiring = identity;
  47. /**
  48. * @category instances
  49. * @since 2.6.0
  50. */
  51. export var getRing = identity;
  52. /**
  53. * @category instances
  54. * @since 2.6.0
  55. */
  56. export var getHeytingAlgebra = identity;
  57. /**
  58. * @category instances
  59. * @since 2.6.0
  60. */
  61. export var getBooleanAlgebra = identity;
  62. /**
  63. * @category instances
  64. * @since 2.0.0
  65. */
  66. export function getApply(S) {
  67. return {
  68. URI: URI,
  69. _E: undefined,
  70. map: _map,
  71. ap: function (fab, fa) { return make(S.concat(fab, fa)); }
  72. };
  73. }
  74. /**
  75. * @category instances
  76. * @since 2.0.0
  77. */
  78. export function getApplicative(M) {
  79. var A = getApply(M);
  80. return {
  81. URI: URI,
  82. _E: undefined,
  83. map: A.map,
  84. ap: A.ap,
  85. of: function () { return make(M.empty); }
  86. };
  87. }
  88. var _contramap = function (fa, f) { return pipe(fa, contramap(f)); };
  89. /* istanbul ignore next */
  90. var _map = function (fa, f) { return pipe(fa, map(f)); };
  91. /* istanbul ignore next */
  92. var _bimap = function (fa, f, g) { return pipe(fa, bimap(f, g)); };
  93. /* istanbul ignore next */
  94. var _mapLeft = function (fa, f) { return pipe(fa, mapLeft(f)); };
  95. /**
  96. * @since 2.0.0
  97. */
  98. export var contramap = function () { return unsafeCoerce; };
  99. /**
  100. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  101. * use the type constructor `F` to represent some computational context.
  102. *
  103. * @category mapping
  104. * @since 2.0.0
  105. */
  106. export var map = function () { return unsafeCoerce; };
  107. /**
  108. * Map a pair of functions over the two type arguments of the bifunctor.
  109. *
  110. * @category mapping
  111. * @since 2.6.2
  112. */
  113. export var bimap = function (f) { return function (fa) {
  114. return make(f(fa));
  115. }; };
  116. /**
  117. * Map a function over the first type argument of a bifunctor.
  118. *
  119. * @category error handling
  120. * @since 2.6.2
  121. */
  122. export var mapLeft = function (f) { return function (fa) { return make(f(fa)); }; };
  123. /**
  124. * @category type lambdas
  125. * @since 2.0.0
  126. */
  127. export var URI = 'Const';
  128. /**
  129. * @category instances
  130. * @since 2.7.0
  131. */
  132. export var Functor = {
  133. URI: URI,
  134. map: _map
  135. };
  136. /**
  137. * @category mapping
  138. * @since 2.10.0
  139. */
  140. export var flap = /*#__PURE__*/ flap_(Functor);
  141. /**
  142. * @category instances
  143. * @since 2.7.0
  144. */
  145. export var Contravariant = {
  146. URI: URI,
  147. contramap: _contramap
  148. };
  149. /**
  150. * @category instances
  151. * @since 2.7.0
  152. */
  153. export var Bifunctor = {
  154. URI: URI,
  155. bimap: _bimap,
  156. mapLeft: _mapLeft
  157. };
  158. // -------------------------------------------------------------------------------------
  159. // deprecated
  160. // -------------------------------------------------------------------------------------
  161. /**
  162. * This instance is deprecated, use small, specific instances instead.
  163. * For example if a function needs a `Functor` instance, pass `C.Functor` instead of `C.const_`
  164. * (where `C` is from `import C from 'fp-ts/Const'`)
  165. *
  166. * @category zone of death
  167. * @since 2.0.0
  168. * @deprecated
  169. */
  170. export var const_ = {
  171. URI: URI,
  172. map: _map,
  173. contramap: _contramap,
  174. bimap: _bimap,
  175. mapLeft: _mapLeft
  176. };