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

pipeable.js 8.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.pipe = exports.pipeable = exports.compose = exports.promap = exports.partitionMapWithIndex = exports.partitionWithIndex = exports.filterMapWithIndex = exports.filterWithIndex = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.alt = exports.reduceRightWithIndex = exports.foldMapWithIndex = exports.reduceWithIndex = exports.reduceRight = exports.foldMap = exports.reduce = exports.extend = exports.mapLeft = exports.bimap = exports.chain = exports.ap = exports.mapWithIndex = exports.contramap = exports.map = void 0;
  4. var Apply_1 = require("./Apply");
  5. var Chain_1 = require("./Chain");
  6. var function_1 = require("./function");
  7. function map(F) {
  8. return function (f) { return function (fa) { return F.map(fa, f); }; };
  9. }
  10. exports.map = map;
  11. function contramap(F) {
  12. return function (f) { return function (fa) { return F.contramap(fa, f); }; };
  13. }
  14. exports.contramap = contramap;
  15. function mapWithIndex(F) {
  16. return function (f) { return function (fa) { return F.mapWithIndex(fa, f); }; };
  17. }
  18. exports.mapWithIndex = mapWithIndex;
  19. function ap(F) {
  20. return function (fa) { return function (fab) { return F.ap(fab, fa); }; };
  21. }
  22. exports.ap = ap;
  23. function chain(F) {
  24. return function (f) { return function (fa) { return F.chain(fa, f); }; };
  25. }
  26. exports.chain = chain;
  27. function bimap(F) {
  28. return function (f, g) { return function (fea) { return F.bimap(fea, f, g); }; };
  29. }
  30. exports.bimap = bimap;
  31. function mapLeft(F) {
  32. return function (f) { return function (fea) { return F.mapLeft(fea, f); }; };
  33. }
  34. exports.mapLeft = mapLeft;
  35. function extend(F) {
  36. return function (f) { return function (wa) { return F.extend(wa, f); }; };
  37. }
  38. exports.extend = extend;
  39. function reduce(F) {
  40. return function (b, f) { return function (fa) { return F.reduce(fa, b, f); }; };
  41. }
  42. exports.reduce = reduce;
  43. function foldMap(F) {
  44. return function (M) {
  45. var foldMapM = F.foldMap(M);
  46. return function (f) { return function (fa) { return foldMapM(fa, f); }; };
  47. };
  48. }
  49. exports.foldMap = foldMap;
  50. function reduceRight(F) {
  51. return function (b, f) { return function (fa) { return F.reduceRight(fa, b, f); }; };
  52. }
  53. exports.reduceRight = reduceRight;
  54. function reduceWithIndex(F) {
  55. return function (b, f) { return function (fa) { return F.reduceWithIndex(fa, b, f); }; };
  56. }
  57. exports.reduceWithIndex = reduceWithIndex;
  58. function foldMapWithIndex(F) {
  59. return function (M) {
  60. var foldMapWithIndexM = F.foldMapWithIndex(M);
  61. return function (f) { return function (fa) { return foldMapWithIndexM(fa, f); }; };
  62. };
  63. }
  64. exports.foldMapWithIndex = foldMapWithIndex;
  65. function reduceRightWithIndex(F) {
  66. return function (b, f) { return function (fa) { return F.reduceRightWithIndex(fa, b, f); }; };
  67. }
  68. exports.reduceRightWithIndex = reduceRightWithIndex;
  69. function alt(F) {
  70. return function (that) { return function (fa) { return F.alt(fa, that); }; };
  71. }
  72. exports.alt = alt;
  73. function filter(F) {
  74. return function (predicate) { return function (fa) { return F.filter(fa, predicate); }; };
  75. }
  76. exports.filter = filter;
  77. function filterMap(F) {
  78. return function (f) { return function (fa) { return F.filterMap(fa, f); }; };
  79. }
  80. exports.filterMap = filterMap;
  81. function partition(F) {
  82. return function (f) { return function (fa) { return F.partition(fa, f); }; };
  83. }
  84. exports.partition = partition;
  85. function partitionMap(F) {
  86. return function (f) { return function (fa) { return F.partitionMap(fa, f); }; };
  87. }
  88. exports.partitionMap = partitionMap;
  89. function filterWithIndex(F) {
  90. return function (predicate) { return function (fa) { return F.filterWithIndex(fa, predicate); }; };
  91. }
  92. exports.filterWithIndex = filterWithIndex;
  93. function filterMapWithIndex(F) {
  94. return function (f) { return function (fa) { return F.filterMapWithIndex(fa, f); }; };
  95. }
  96. exports.filterMapWithIndex = filterMapWithIndex;
  97. function partitionWithIndex(F) {
  98. return function (f) { return function (fa) { return F.partitionWithIndex(fa, f); }; };
  99. }
  100. exports.partitionWithIndex = partitionWithIndex;
  101. function partitionMapWithIndex(F) {
  102. return function (f) { return function (fa) { return F.partitionMapWithIndex(fa, f); }; };
  103. }
  104. exports.partitionMapWithIndex = partitionMapWithIndex;
  105. function promap(F) {
  106. return function (f, g) { return function (fbc) { return F.promap(fbc, f, g); }; };
  107. }
  108. exports.promap = promap;
  109. function compose(F) {
  110. return function (ea) { return function (ab) { return F.compose(ab, ea); }; };
  111. }
  112. exports.compose = compose;
  113. var isFunctor = function (I) { return typeof I.map === 'function'; };
  114. var isContravariant = function (I) { return typeof I.contramap === 'function'; };
  115. var isFunctorWithIndex = function (I) { return typeof I.mapWithIndex === 'function'; };
  116. var isApply = function (I) { return typeof I.ap === 'function'; };
  117. var isChain = function (I) { return typeof I.chain === 'function'; };
  118. var isBifunctor = function (I) { return typeof I.bimap === 'function'; };
  119. var isExtend = function (I) { return typeof I.extend === 'function'; };
  120. var isFoldable = function (I) { return typeof I.reduce === 'function'; };
  121. var isFoldableWithIndex = function (I) { return typeof I.reduceWithIndex === 'function'; };
  122. var isAlt = function (I) { return typeof I.alt === 'function'; };
  123. var isCompactable = function (I) { return typeof I.compact === 'function'; };
  124. var isFilterable = function (I) { return typeof I.filter === 'function'; };
  125. var isFilterableWithIndex = function (I) {
  126. return typeof I.filterWithIndex === 'function';
  127. };
  128. var isProfunctor = function (I) { return typeof I.promap === 'function'; };
  129. var isSemigroupoid = function (I) { return typeof I.compose === 'function'; };
  130. var isMonadThrow = function (I) { return typeof I.throwError === 'function'; };
  131. /** @deprecated */
  132. function pipeable(I) {
  133. var r = {};
  134. if (isFunctor(I)) {
  135. r.map = map(I);
  136. }
  137. if (isContravariant(I)) {
  138. r.contramap = contramap(I);
  139. }
  140. if (isFunctorWithIndex(I)) {
  141. r.mapWithIndex = mapWithIndex(I);
  142. }
  143. if (isApply(I)) {
  144. r.ap = ap(I);
  145. r.apFirst = (0, Apply_1.apFirst)(I);
  146. r.apSecond = (0, Apply_1.apSecond)(I);
  147. }
  148. if (isChain(I)) {
  149. r.chain = chain(I);
  150. r.chainFirst = (0, Chain_1.chainFirst)(I);
  151. r.flatten = r.chain(function_1.identity);
  152. }
  153. if (isBifunctor(I)) {
  154. r.bimap = bimap(I);
  155. r.mapLeft = mapLeft(I);
  156. }
  157. if (isExtend(I)) {
  158. r.extend = extend(I);
  159. r.duplicate = r.extend(function_1.identity);
  160. }
  161. if (isFoldable(I)) {
  162. r.reduce = reduce(I);
  163. r.foldMap = foldMap(I);
  164. r.reduceRight = reduceRight(I);
  165. }
  166. if (isFoldableWithIndex(I)) {
  167. r.reduceWithIndex = reduceWithIndex(I);
  168. r.foldMapWithIndex = foldMapWithIndex(I);
  169. r.reduceRightWithIndex = reduceRightWithIndex(I);
  170. }
  171. if (isAlt(I)) {
  172. r.alt = alt(I);
  173. }
  174. if (isCompactable(I)) {
  175. r.compact = I.compact;
  176. r.separate = I.separate;
  177. }
  178. if (isFilterable(I)) {
  179. r.filter = filter(I);
  180. r.filterMap = filterMap(I);
  181. r.partition = partition(I);
  182. r.partitionMap = partitionMap(I);
  183. }
  184. if (isFilterableWithIndex(I)) {
  185. r.filterWithIndex = filterWithIndex(I);
  186. r.filterMapWithIndex = filterMapWithIndex(I);
  187. r.partitionWithIndex = partitionWithIndex(I);
  188. r.partitionMapWithIndex = partitionMapWithIndex(I);
  189. }
  190. if (isProfunctor(I)) {
  191. r.promap = promap(I);
  192. }
  193. if (isSemigroupoid(I)) {
  194. r.compose = compose(I);
  195. }
  196. if (isMonadThrow(I)) {
  197. var fromOption = function (onNone) { return function (ma) {
  198. return ma._tag === 'None' ? I.throwError(onNone()) : I.of(ma.value);
  199. }; };
  200. var fromEither = function (ma) {
  201. return ma._tag === 'Left' ? I.throwError(ma.left) : I.of(ma.right);
  202. };
  203. var fromPredicate = function (predicate, onFalse) {
  204. return function (a) {
  205. return predicate(a) ? I.of(a) : I.throwError(onFalse(a));
  206. };
  207. };
  208. var filterOrElse = function (predicate, onFalse) {
  209. return function (ma) {
  210. return I.chain(ma, function (a) { return (predicate(a) ? I.of(a) : I.throwError(onFalse(a))); });
  211. };
  212. };
  213. r.fromOption = fromOption;
  214. r.fromEither = fromEither;
  215. r.fromPredicate = fromPredicate;
  216. r.filterOrElse = filterOrElse;
  217. }
  218. return r;
  219. }
  220. exports.pipeable = pipeable;
  221. /**
  222. * Use [`pipe`](https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe) from `function` module instead.
  223. *
  224. * @since 2.0.0
  225. * @deprecated
  226. */
  227. exports.pipe = function_1.pipe;