版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

96 строки
2.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.and = exports.or = exports.not = exports.Contravariant = exports.getMonoidAll = exports.getSemigroupAll = exports.getMonoidAny = exports.getSemigroupAny = exports.URI = exports.contramap = void 0;
  4. var function_1 = require("./function");
  5. var contramap_ = function (predicate, f) { return (0, function_1.pipe)(predicate, (0, exports.contramap)(f)); };
  6. /**
  7. * @since 2.11.0
  8. */
  9. var contramap = function (f) {
  10. return function (predicate) {
  11. return (0, function_1.flow)(f, predicate);
  12. };
  13. };
  14. exports.contramap = contramap;
  15. /**
  16. * @category type lambdas
  17. * @since 2.11.0
  18. */
  19. exports.URI = 'Predicate';
  20. /**
  21. * @category instances
  22. * @since 2.11.0
  23. */
  24. var getSemigroupAny = function () { return ({
  25. concat: function (first, second) { return (0, function_1.pipe)(first, (0, exports.or)(second)); }
  26. }); };
  27. exports.getSemigroupAny = getSemigroupAny;
  28. /**
  29. * @category instances
  30. * @since 2.11.0
  31. */
  32. var getMonoidAny = function () { return ({
  33. concat: (0, exports.getSemigroupAny)().concat,
  34. empty: function_1.constFalse
  35. }); };
  36. exports.getMonoidAny = getMonoidAny;
  37. /**
  38. * @category instances
  39. * @since 2.11.0
  40. */
  41. var getSemigroupAll = function () { return ({
  42. concat: function (first, second) { return (0, function_1.pipe)(first, (0, exports.and)(second)); }
  43. }); };
  44. exports.getSemigroupAll = getSemigroupAll;
  45. /**
  46. * @category instances
  47. * @since 2.11.0
  48. */
  49. var getMonoidAll = function () { return ({
  50. concat: (0, exports.getSemigroupAll)().concat,
  51. empty: function_1.constTrue
  52. }); };
  53. exports.getMonoidAll = getMonoidAll;
  54. /**
  55. * @category instances
  56. * @since 2.11.0
  57. */
  58. exports.Contravariant = {
  59. URI: exports.URI,
  60. contramap: contramap_
  61. };
  62. // -------------------------------------------------------------------------------------
  63. // utils
  64. // -------------------------------------------------------------------------------------
  65. /**
  66. * @since 2.11.0
  67. */
  68. var not = function (predicate) {
  69. return function (a) {
  70. return !predicate(a);
  71. };
  72. };
  73. exports.not = not;
  74. /**
  75. * @since 2.11.0
  76. */
  77. var or = function (second) {
  78. return function (first) {
  79. return function (a) {
  80. return first(a) || second(a);
  81. };
  82. };
  83. };
  84. exports.or = or;
  85. /**
  86. * @since 2.11.0
  87. */
  88. var and = function (second) {
  89. return function (first) {
  90. return function (a) {
  91. return first(a) && second(a);
  92. };
  93. };
  94. };
  95. exports.and = and;