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

77 regels
2.8 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getStateM = exports.execute = exports.evaluate = exports.fromF = exports.fromState = exports.chain = exports.ap = exports.map = exports.of = void 0;
  4. var function_1 = require("./function");
  5. var ReadonlyTuple_1 = require("./ReadonlyTuple");
  6. function of(F) {
  7. return function (a) { return function (s) { return F.of([a, s]); }; };
  8. }
  9. exports.of = of;
  10. function map(F) {
  11. return function (f) { return function (fa) { return function (s) { return F.map(fa(s), function (_a) {
  12. var a = _a[0], s1 = _a[1];
  13. return [f(a), s1];
  14. }); }; }; };
  15. }
  16. exports.map = map;
  17. function ap(M) {
  18. return function (fa) { return function (fab) { return function (s) { return M.chain(fab(s), function (_a) {
  19. var f = _a[0], s = _a[1];
  20. return M.map(fa(s), function (_a) {
  21. var a = _a[0], s = _a[1];
  22. return [f(a), s];
  23. });
  24. }); }; }; };
  25. }
  26. exports.ap = ap;
  27. function chain(M) {
  28. return function (f) { return function (ma) { return function (s) { return M.chain(ma(s), function (_a) {
  29. var a = _a[0], s1 = _a[1];
  30. return f(a)(s1);
  31. }); }; }; };
  32. }
  33. exports.chain = chain;
  34. function fromState(F) {
  35. return function (sa) { return function (s) { return F.of(sa(s)); }; };
  36. }
  37. exports.fromState = fromState;
  38. function fromF(F) {
  39. return function (ma) { return function (s) { return F.map(ma, function (a) { return [a, s]; }); }; };
  40. }
  41. exports.fromF = fromF;
  42. function evaluate(F) {
  43. return function (s) { return function (ma) { return F.map(ma(s), function (_a) {
  44. var a = _a[0];
  45. return a;
  46. }); }; };
  47. }
  48. exports.evaluate = evaluate;
  49. function execute(F) {
  50. return function (s) { return function (ma) { return F.map(ma(s), ReadonlyTuple_1.snd); }; };
  51. }
  52. exports.execute = execute;
  53. /** @deprecated */
  54. /* istanbul ignore next */
  55. function getStateM(M) {
  56. var _ap = ap(M);
  57. var _map = map(M);
  58. var _chain = chain(M);
  59. var _evaluate = evaluate(M);
  60. var _execute = execute(M);
  61. return {
  62. map: function (fa, f) { return (0, function_1.pipe)(fa, _map(f)); },
  63. ap: function (fab, fa) { return (0, function_1.pipe)(fab, _ap(fa)); },
  64. of: of(M),
  65. chain: function (ma, f) { return (0, function_1.pipe)(ma, _chain(f)); },
  66. get: function () { return function (s) { return M.of([s, s]); }; },
  67. put: function (s) { return function () { return M.of([undefined, s]); }; },
  68. modify: function (f) { return function (s) { return M.of([undefined, f(s)]); }; },
  69. gets: function (f) { return function (s) { return M.of([f(s), s]); }; },
  70. fromState: fromState(M),
  71. fromM: fromF(M),
  72. evalState: function (fa, s) { return (0, function_1.pipe)(fa, _evaluate(s)); },
  73. execState: function (fa, s) { return (0, function_1.pipe)(fa, _execute(s)); }
  74. };
  75. }
  76. exports.getStateM = getStateM;