版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

358 righe
9.5 KiB

  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.identity = exports.apS = exports.bind = exports.let = exports.bindTo = exports.Do = exports.ChainRec = exports.Comonad = exports.Alt = exports.Traversable = exports.Foldable = exports.chainFirst = exports.Monad = exports.Chain = exports.Applicative = exports.apSecond = exports.apFirst = exports.Apply = exports.Pointed = exports.flap = exports.Functor = exports.getEq = exports.getShow = exports.URI = exports.alt = exports.altW = exports.sequence = exports.traverse = exports.reduceRight = exports.foldMap = exports.reduce = exports.flatten = exports.duplicate = exports.extract = exports.extend = exports.chain = exports.of = exports.ap = exports.map = void 0;
  27. var Apply_1 = require("./Apply");
  28. var Chain_1 = require("./Chain");
  29. var ChainRec_1 = require("./ChainRec");
  30. var function_1 = require("./function");
  31. var Functor_1 = require("./Functor");
  32. var _ = __importStar(require("./internal"));
  33. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  34. var _ap = function (fab, fa) { return (0, function_1.pipe)(fab, (0, exports.ap)(fa)); };
  35. var _chain = function (ma, f) { return (0, function_1.pipe)(ma, (0, exports.chain)(f)); };
  36. /* istanbul ignore next */
  37. var _reduce = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduce)(b, f)); };
  38. /* istanbul ignore next */
  39. var _foldMap = function (M) { return function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.foldMap)(M)(f)); }; };
  40. /* istanbul ignore next */
  41. var _reduceRight = function (fa, b, f) { return (0, function_1.pipe)(fa, (0, exports.reduceRight)(b, f)); };
  42. /* istanbul ignore next */
  43. var _alt = function (fa, that) { return (0, function_1.pipe)(fa, (0, exports.alt)(that)); };
  44. /* istanbul ignore next */
  45. var _extend = function (wa, f) { return (0, function_1.pipe)(wa, (0, exports.extend)(f)); };
  46. /* istanbul ignore next */
  47. var _traverse = function (F) {
  48. var traverseF = (0, exports.traverse)(F);
  49. return function (ta, f) { return (0, function_1.pipe)(ta, traverseF(f)); };
  50. };
  51. var _chainRec = ChainRec_1.tailRec;
  52. /**
  53. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  54. * use the type constructor `F` to represent some computational context.
  55. *
  56. * @category mapping
  57. * @since 2.0.0
  58. */
  59. var map = function (f) { return function (fa) { return f(fa); }; };
  60. exports.map = map;
  61. /**
  62. * @since 2.0.0
  63. */
  64. var ap = function (fa) { return function (fab) { return fab(fa); }; };
  65. exports.ap = ap;
  66. /**
  67. * @category constructors
  68. * @since 2.0.0
  69. */
  70. exports.of = function_1.identity;
  71. /**
  72. * Composes computations in sequence, using the return value of one computation to determine the next computation.
  73. *
  74. * @category sequencing
  75. * @since 2.0.0
  76. */
  77. var chain = function (f) { return function (ma) { return f(ma); }; };
  78. exports.chain = chain;
  79. /**
  80. * @since 2.0.0
  81. */
  82. var extend = function (f) { return function (wa) { return f(wa); }; };
  83. exports.extend = extend;
  84. /**
  85. * @category Extract
  86. * @since 2.6.2
  87. */
  88. exports.extract = function_1.identity;
  89. /**
  90. * @since 2.0.0
  91. */
  92. exports.duplicate = (0, exports.extend)(function_1.identity);
  93. /**
  94. * @category sequencing
  95. * @since 2.0.0
  96. */
  97. exports.flatten = (0, exports.chain)(function_1.identity);
  98. /**
  99. * @category folding
  100. * @since 2.0.0
  101. */
  102. var reduce = function (b, f) { return function (fa) { return f(b, fa); }; };
  103. exports.reduce = reduce;
  104. /**
  105. * @category folding
  106. * @since 2.0.0
  107. */
  108. var foldMap = function () { return function (f) { return function (fa) { return f(fa); }; }; };
  109. exports.foldMap = foldMap;
  110. /**
  111. * @category folding
  112. * @since 2.0.0
  113. */
  114. var reduceRight = function (b, f) { return function (fa) { return f(fa, b); }; };
  115. exports.reduceRight = reduceRight;
  116. /**
  117. * @category traversing
  118. * @since 2.6.3
  119. */
  120. var traverse = function (F) {
  121. return function (f) {
  122. return function (ta) {
  123. return F.map(f(ta), function_1.identity);
  124. };
  125. };
  126. };
  127. exports.traverse = traverse;
  128. /**
  129. * @category traversing
  130. * @since 2.6.3
  131. */
  132. var sequence = function (F) {
  133. return function (ta) {
  134. return F.map(ta, function_1.identity);
  135. };
  136. };
  137. exports.sequence = sequence;
  138. /**
  139. * Less strict version of [`alt`](#alt).
  140. *
  141. * The `W` suffix (short for **W**idening) means that the return types will be merged.
  142. *
  143. * @category error handling
  144. * @since 2.9.0
  145. */
  146. var altW = function () { return function_1.identity; };
  147. exports.altW = altW;
  148. /**
  149. * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
  150. * types of kind `* -> *`.
  151. *
  152. * @category error handling
  153. * @since 2.0.0
  154. */
  155. exports.alt = exports.altW;
  156. /**
  157. * @category type lambdas
  158. * @since 2.0.0
  159. */
  160. exports.URI = 'Identity';
  161. /**
  162. * @category instances
  163. * @since 2.0.0
  164. */
  165. exports.getShow = function_1.identity;
  166. /**
  167. * @category instances
  168. * @since 2.0.0
  169. */
  170. exports.getEq = function_1.identity;
  171. /**
  172. * @category instances
  173. * @since 2.7.0
  174. */
  175. exports.Functor = {
  176. URI: exports.URI,
  177. map: _map
  178. };
  179. /**
  180. * @category mapping
  181. * @since 2.10.0
  182. */
  183. exports.flap = (0, Functor_1.flap)(exports.Functor);
  184. /**
  185. * @category instances
  186. * @since 2.10.0
  187. */
  188. exports.Pointed = {
  189. URI: exports.URI,
  190. of: exports.of
  191. };
  192. /**
  193. * @category instances
  194. * @since 2.10.0
  195. */
  196. exports.Apply = {
  197. URI: exports.URI,
  198. map: _map,
  199. ap: _ap
  200. };
  201. /**
  202. * Combine two effectful actions, keeping only the result of the first.
  203. *
  204. * @since 2.0.0
  205. */
  206. exports.apFirst = (0, Apply_1.apFirst)(exports.Apply);
  207. /**
  208. * Combine two effectful actions, keeping only the result of the second.
  209. *
  210. * @since 2.0.0
  211. */
  212. exports.apSecond = (0, Apply_1.apSecond)(exports.Apply);
  213. /**
  214. * @category instances
  215. * @since 2.7.0
  216. */
  217. exports.Applicative = {
  218. URI: exports.URI,
  219. map: _map,
  220. ap: _ap,
  221. of: exports.of
  222. };
  223. /**
  224. * @category instances
  225. * @since 2.10.0
  226. */
  227. exports.Chain = {
  228. URI: exports.URI,
  229. map: _map,
  230. ap: _ap,
  231. chain: _chain
  232. };
  233. /**
  234. * @category instances
  235. * @since 2.7.0
  236. */
  237. exports.Monad = {
  238. URI: exports.URI,
  239. map: _map,
  240. ap: _ap,
  241. of: exports.of,
  242. chain: _chain
  243. };
  244. /**
  245. * Composes computations in sequence, using the return value of one computation to determine the next computation and
  246. * keeping only the result of the first.
  247. *
  248. * @category sequencing
  249. * @since 2.0.0
  250. */
  251. exports.chainFirst = (0, Chain_1.chainFirst)(exports.Chain);
  252. /**
  253. * @category instances
  254. * @since 2.7.0
  255. */
  256. exports.Foldable = {
  257. URI: exports.URI,
  258. reduce: _reduce,
  259. foldMap: _foldMap,
  260. reduceRight: _reduceRight
  261. };
  262. /**
  263. * @category instances
  264. * @since 2.7.0
  265. */
  266. exports.Traversable = {
  267. URI: exports.URI,
  268. map: _map,
  269. reduce: _reduce,
  270. foldMap: _foldMap,
  271. reduceRight: _reduceRight,
  272. traverse: _traverse,
  273. sequence: exports.sequence
  274. };
  275. /**
  276. * @category instances
  277. * @since 2.7.0
  278. */
  279. exports.Alt = {
  280. URI: exports.URI,
  281. map: _map,
  282. alt: _alt
  283. };
  284. /**
  285. * @category instances
  286. * @since 2.7.0
  287. */
  288. exports.Comonad = {
  289. URI: exports.URI,
  290. map: _map,
  291. extend: _extend,
  292. extract: exports.extract
  293. };
  294. /**
  295. * @category instances
  296. * @since 2.7.0
  297. */
  298. exports.ChainRec = {
  299. URI: exports.URI,
  300. map: _map,
  301. ap: _ap,
  302. chain: _chain,
  303. chainRec: _chainRec
  304. };
  305. // -------------------------------------------------------------------------------------
  306. // do notation
  307. // -------------------------------------------------------------------------------------
  308. /**
  309. * @category do notation
  310. * @since 2.9.0
  311. */
  312. exports.Do = (0, exports.of)(_.emptyRecord);
  313. /**
  314. * @category do notation
  315. * @since 2.8.0
  316. */
  317. exports.bindTo = (0, Functor_1.bindTo)(exports.Functor);
  318. var let_ = /*#__PURE__*/ (0, Functor_1.let)(exports.Functor);
  319. exports.let = let_;
  320. /**
  321. * @category do notation
  322. * @since 2.8.0
  323. */
  324. exports.bind = (0, Chain_1.bind)(exports.Chain);
  325. /**
  326. * @category do notation
  327. * @since 2.8.0
  328. */
  329. exports.apS = (0, Apply_1.apS)(exports.Apply);
  330. // -------------------------------------------------------------------------------------
  331. // deprecated
  332. // -------------------------------------------------------------------------------------
  333. /**
  334. * This instance is deprecated, use small, specific instances instead.
  335. * For example if a function needs a `Functor` instance, pass `I.Functor` instead of `I.identity`
  336. * (where `I` is from `import I from 'fp-ts/Identity'`)
  337. *
  338. * @category zone of death
  339. * @since 2.0.0
  340. * @deprecated
  341. */
  342. exports.identity = {
  343. URI: exports.URI,
  344. map: _map,
  345. ap: _ap,
  346. of: exports.of,
  347. chain: _chain,
  348. reduce: _reduce,
  349. foldMap: _foldMap,
  350. reduceRight: _reduceRight,
  351. traverse: _traverse,
  352. sequence: exports.sequence,
  353. alt: _alt,
  354. extract: exports.extract,
  355. extend: _extend,
  356. chainRec: _chainRec
  357. };