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

187 lines
4.7 KiB

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