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

99 lines
2.7 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.monoidOrdering = exports.eqOrdering = exports.semigroupOrdering = exports.invert = exports.sign = exports.Monoid = exports.Semigroup = exports.Eq = exports.reverse = exports.match = exports.matchW = void 0;
  4. /**
  5. * Less strict version of [`match`](#match).
  6. *
  7. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  8. *
  9. * @category pattern matching
  10. * @since 2.12.0
  11. */
  12. var matchW = function (onLessThan, onEqual, onGreaterThan) {
  13. return function (o) {
  14. return o === -1 ? onLessThan() : o === 0 ? onEqual() : onGreaterThan();
  15. };
  16. };
  17. exports.matchW = matchW;
  18. /**
  19. * @category pattern matching
  20. * @since 2.10.0
  21. */
  22. exports.match = exports.matchW;
  23. // -------------------------------------------------------------------------------------
  24. // combinators
  25. // -------------------------------------------------------------------------------------
  26. /**
  27. * @since 2.10.0
  28. */
  29. var reverse = function (o) { return (o === -1 ? 1 : o === 1 ? -1 : 0); };
  30. exports.reverse = reverse;
  31. // -------------------------------------------------------------------------------------
  32. // instances
  33. // -------------------------------------------------------------------------------------
  34. /**
  35. * @category instances
  36. * @since 2.10.0
  37. */
  38. exports.Eq = {
  39. equals: function (x, y) { return x === y; }
  40. };
  41. /**
  42. * @category instances
  43. * @since 2.10.0
  44. */
  45. exports.Semigroup = {
  46. concat: function (x, y) { return (x !== 0 ? x : y); }
  47. };
  48. /**
  49. * @category instances
  50. * @since 2.10.0
  51. */
  52. exports.Monoid = {
  53. concat: exports.Semigroup.concat,
  54. empty: 0
  55. };
  56. // -------------------------------------------------------------------------------------
  57. // utils
  58. // -------------------------------------------------------------------------------------
  59. /**
  60. * @since 2.0.0
  61. */
  62. var sign = function (n) { return (n <= -1 ? -1 : n >= 1 ? 1 : 0); };
  63. exports.sign = sign;
  64. // -------------------------------------------------------------------------------------
  65. // deprecated
  66. // -------------------------------------------------------------------------------------
  67. /**
  68. * Use [`reverse`](#reverse) instead.
  69. *
  70. * @category zone of death
  71. * @since 2.0.0
  72. * @deprecated
  73. */
  74. exports.invert = exports.reverse;
  75. /**
  76. * Use [`Semigroup`](#semigroup) instead
  77. *
  78. * @category zone of death
  79. * @since 2.0.0
  80. * @deprecated
  81. */
  82. exports.semigroupOrdering = exports.Semigroup;
  83. /**
  84. * Use [`Eq`](#eq) instead
  85. *
  86. * @category zone of death
  87. * @since 2.0.0
  88. * @deprecated
  89. */
  90. exports.eqOrdering = exports.Eq;
  91. /**
  92. * Use [`Monoid`](#monoid) instead
  93. *
  94. * @category zone of death
  95. * @since 2.4.0
  96. * @deprecated
  97. */
  98. exports.monoidOrdering = exports.Monoid;