版博士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 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Show = exports.Ord = exports.MonoidAny = exports.MonoidAll = exports.SemigroupAny = exports.SemigroupAll = exports.BooleanAlgebra = exports.Eq = exports.fold = exports.match = exports.foldW = exports.matchW = exports.isBoolean = void 0;
  4. // -------------------------------------------------------------------------------------
  5. // refinements
  6. // -------------------------------------------------------------------------------------
  7. /**
  8. * @category refinements
  9. * @since 2.11.0
  10. */
  11. var isBoolean = function (u) { return typeof u === 'boolean'; };
  12. exports.isBoolean = isBoolean;
  13. /**
  14. * Less strict version of [`match`](#match).
  15. *
  16. * The `W` suffix (short for **W**idening) means that the handler return types will be merged.
  17. *
  18. * @category pattern matching
  19. * @since 2.10.0
  20. */
  21. var matchW = function (onFalse, onTrue) {
  22. return function (value) {
  23. return value ? onTrue() : onFalse();
  24. };
  25. };
  26. exports.matchW = matchW;
  27. /**
  28. * Alias of [`matchW`](#matchw).
  29. *
  30. * @category pattern matching
  31. * @since 2.10.0
  32. */
  33. exports.foldW = exports.matchW;
  34. /**
  35. * Defines the fold over a boolean value.
  36. * Takes two thunks `onTrue`, `onFalse` and a `boolean` value.
  37. * If `value` is false, `onFalse()` is returned, otherwise `onTrue()`.
  38. *
  39. * @example
  40. * import { some, map } from 'fp-ts/Option'
  41. * import { pipe } from 'fp-ts/function'
  42. * import { match } from 'fp-ts/boolean'
  43. *
  44. * assert.deepStrictEqual(
  45. * pipe(
  46. * some(true),
  47. * map(match(() => 'false', () => 'true'))
  48. * ),
  49. * some('true')
  50. * )
  51. *
  52. * @category pattern matching
  53. * @since 2.10.0
  54. */
  55. exports.match = exports.foldW;
  56. /**
  57. * Alias of [`match`](#match).
  58. *
  59. * @category pattern matching
  60. * @since 2.2.0
  61. */
  62. exports.fold = exports.match;
  63. // -------------------------------------------------------------------------------------
  64. // instances
  65. // -------------------------------------------------------------------------------------
  66. /**
  67. * @category instances
  68. * @since 2.10.0
  69. */
  70. exports.Eq = {
  71. equals: function (first, second) { return first === second; }
  72. };
  73. /**
  74. * @category instances
  75. * @since 2.10.0
  76. */
  77. exports.BooleanAlgebra = {
  78. meet: function (first, second) { return first && second; },
  79. join: function (first, second) { return first || second; },
  80. zero: false,
  81. one: true,
  82. implies: function (first, second) { return !first || second; },
  83. not: function (b) { return !b; }
  84. };
  85. /**
  86. * `boolean` semigroup under conjunction.
  87. *
  88. * @example
  89. * import { SemigroupAll } from 'fp-ts/boolean'
  90. *
  91. * assert.deepStrictEqual(SemigroupAll.concat(true, true), true)
  92. * assert.deepStrictEqual(SemigroupAll.concat(true, false), false)
  93. *
  94. * @category instances
  95. * @since 2.10.0
  96. */
  97. exports.SemigroupAll = {
  98. concat: function (first, second) { return first && second; }
  99. };
  100. /**
  101. * `boolean` semigroup under disjunction.
  102. *
  103. * @example
  104. * import { SemigroupAny } from 'fp-ts/boolean'
  105. *
  106. * assert.deepStrictEqual(SemigroupAny.concat(true, true), true)
  107. * assert.deepStrictEqual(SemigroupAny.concat(true, false), true)
  108. * assert.deepStrictEqual(SemigroupAny.concat(false, false), false)
  109. *
  110. * @category instances
  111. * @since 2.10.0
  112. */
  113. exports.SemigroupAny = {
  114. concat: function (first, second) { return first || second; }
  115. };
  116. /**
  117. * `boolean` monoid under conjunction.
  118. *
  119. * The `empty` value is `true`.
  120. *
  121. * @example
  122. * import { MonoidAll } from 'fp-ts/boolean'
  123. *
  124. * assert.deepStrictEqual(MonoidAll.concat(true, true), true)
  125. * assert.deepStrictEqual(MonoidAll.concat(true, false), false)
  126. *
  127. * @category instances
  128. * @since 2.10.0
  129. */
  130. exports.MonoidAll = {
  131. concat: exports.SemigroupAll.concat,
  132. empty: true
  133. };
  134. /**
  135. * `boolean` monoid under disjunction.
  136. *
  137. * The `empty` value is `false`.
  138. *
  139. * @example
  140. * import { MonoidAny } from 'fp-ts/boolean'
  141. *
  142. * assert.deepStrictEqual(MonoidAny.concat(true, true), true)
  143. * assert.deepStrictEqual(MonoidAny.concat(true, false), true)
  144. * assert.deepStrictEqual(MonoidAny.concat(false, false), false)
  145. *
  146. * @category instances
  147. * @since 2.10.0
  148. */
  149. exports.MonoidAny = {
  150. concat: exports.SemigroupAny.concat,
  151. empty: false
  152. };
  153. /**
  154. * @category instances
  155. * @since 2.10.0
  156. */
  157. exports.Ord = {
  158. equals: exports.Eq.equals,
  159. compare: function (first, second) { return (first < second ? -1 : first > second ? 1 : 0); }
  160. };
  161. /**
  162. * @category instances
  163. * @since 2.10.0
  164. */
  165. exports.Show = {
  166. show: function (b) { return JSON.stringify(b); }
  167. };