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

пре 1 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. /**
  3. * The `FromEither` type class represents those data types which support errors.
  4. *
  5. * @since 2.10.0
  6. */
  7. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  8. if (k2 === undefined) k2 = k;
  9. var desc = Object.getOwnPropertyDescriptor(m, k);
  10. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  11. desc = { enumerable: true, get: function() { return m[k]; } };
  12. }
  13. Object.defineProperty(o, k2, desc);
  14. }) : (function(o, m, k, k2) {
  15. if (k2 === undefined) k2 = k;
  16. o[k2] = m[k];
  17. }));
  18. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  19. Object.defineProperty(o, "default", { enumerable: true, value: v });
  20. }) : function(o, v) {
  21. o["default"] = v;
  22. });
  23. var __importStar = (this && this.__importStar) || function (mod) {
  24. if (mod && mod.__esModule) return mod;
  25. var result = {};
  26. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  27. __setModuleDefault(result, mod);
  28. return result;
  29. };
  30. Object.defineProperty(exports, "__esModule", { value: true });
  31. exports.filterOrElse = exports.chainFirstEitherK = exports.chainEitherK = exports.fromEitherK = exports.chainOptionK = exports.fromOptionK = exports.fromPredicate = exports.fromOption = void 0;
  32. var Chain_1 = require("./Chain");
  33. var function_1 = require("./function");
  34. var _ = __importStar(require("./internal"));
  35. function fromOption(F) {
  36. return function (onNone) { return function (ma) { return F.fromEither(_.isNone(ma) ? _.left(onNone()) : _.right(ma.value)); }; };
  37. }
  38. exports.fromOption = fromOption;
  39. function fromPredicate(F) {
  40. return function (predicate, onFalse) {
  41. return function (a) {
  42. return F.fromEither(predicate(a) ? _.right(a) : _.left(onFalse(a)));
  43. };
  44. };
  45. }
  46. exports.fromPredicate = fromPredicate;
  47. function fromOptionK(F) {
  48. var fromOptionF = fromOption(F);
  49. return function (onNone) {
  50. var from = fromOptionF(onNone);
  51. return function (f) { return (0, function_1.flow)(f, from); };
  52. };
  53. }
  54. exports.fromOptionK = fromOptionK;
  55. function chainOptionK(F, M) {
  56. var fromOptionKF = fromOptionK(F);
  57. return function (onNone) {
  58. var from = fromOptionKF(onNone);
  59. return function (f) { return function (ma) { return M.chain(ma, from(f)); }; };
  60. };
  61. }
  62. exports.chainOptionK = chainOptionK;
  63. function fromEitherK(F) {
  64. return function (f) { return (0, function_1.flow)(f, F.fromEither); };
  65. }
  66. exports.fromEitherK = fromEitherK;
  67. function chainEitherK(F, M) {
  68. var fromEitherKF = fromEitherK(F);
  69. return function (f) { return function (ma) { return M.chain(ma, fromEitherKF(f)); }; };
  70. }
  71. exports.chainEitherK = chainEitherK;
  72. function chainFirstEitherK(F, M) {
  73. return (0, function_1.flow)(fromEitherK(F), (0, Chain_1.chainFirst)(M));
  74. }
  75. exports.chainFirstEitherK = chainFirstEitherK;
  76. function filterOrElse(F, M) {
  77. return function (predicate, onFalse) {
  78. return function (ma) {
  79. return M.chain(ma, function (a) { return F.fromEither(predicate(a) ? _.right(a) : _.left(onFalse(a))); });
  80. };
  81. };
  82. }
  83. exports.filterOrElse = filterOrElse;