版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

312 righe
8.3 KiB

  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.monoidProduct = exports.monoidSum = exports.monoidString = exports.getEndomorphismMonoid = exports.getFunctionMonoid = exports.monoidAny = exports.monoidAll = exports.fold = exports.getMeetMonoid = exports.getJoinMonoid = exports.getDualMonoid = exports.getStructMonoid = exports.getTupleMonoid = exports.monoidVoid = exports.concatAll = exports.tuple = exports.struct = exports.reverse = exports.max = exports.min = void 0;
  27. var function_1 = require("./function");
  28. var Endomorphism_1 = require("./Endomorphism");
  29. var _ = __importStar(require("./internal"));
  30. var Se = __importStar(require("./Semigroup"));
  31. // -------------------------------------------------------------------------------------
  32. // constructors
  33. // -------------------------------------------------------------------------------------
  34. /**
  35. * Get a monoid where `concat` will return the minimum, based on the provided bounded order.
  36. *
  37. * The `empty` value is the `top` value.
  38. *
  39. * @example
  40. * import * as N from 'fp-ts/number'
  41. * import * as M from 'fp-ts/Monoid'
  42. *
  43. * const M1 = M.min(N.Bounded)
  44. *
  45. * assert.deepStrictEqual(M1.concat(1, 2), 1)
  46. *
  47. * @category constructors
  48. * @since 2.10.0
  49. */
  50. var min = function (B) { return ({
  51. concat: Se.min(B).concat,
  52. empty: B.top
  53. }); };
  54. exports.min = min;
  55. /**
  56. * Get a monoid where `concat` will return the maximum, based on the provided bounded order.
  57. *
  58. * The `empty` value is the `bottom` value.
  59. *
  60. * @example
  61. * import * as N from 'fp-ts/number'
  62. * import * as M from 'fp-ts/Monoid'
  63. *
  64. * const M1 = M.max(N.Bounded)
  65. *
  66. * assert.deepStrictEqual(M1.concat(1, 2), 2)
  67. *
  68. * @category constructors
  69. * @since 2.10.0
  70. */
  71. var max = function (B) { return ({
  72. concat: Se.max(B).concat,
  73. empty: B.bottom
  74. }); };
  75. exports.max = max;
  76. // -------------------------------------------------------------------------------------
  77. // combinators
  78. // -------------------------------------------------------------------------------------
  79. /**
  80. * The dual of a `Monoid`, obtained by swapping the arguments of `concat`.
  81. *
  82. * @example
  83. * import { reverse } from 'fp-ts/Monoid'
  84. * import * as S from 'fp-ts/string'
  85. *
  86. * assert.deepStrictEqual(reverse(S.Monoid).concat('a', 'b'), 'ba')
  87. *
  88. * @since 2.10.0
  89. */
  90. var reverse = function (M) { return ({
  91. concat: Se.reverse(M).concat,
  92. empty: M.empty
  93. }); };
  94. exports.reverse = reverse;
  95. /**
  96. * Given a struct of monoids returns a monoid for the struct.
  97. *
  98. * @example
  99. * import { struct } from 'fp-ts/Monoid'
  100. * import * as N from 'fp-ts/number'
  101. *
  102. * interface Point {
  103. * readonly x: number
  104. * readonly y: number
  105. * }
  106. *
  107. * const M = struct<Point>({
  108. * x: N.MonoidSum,
  109. * y: N.MonoidSum
  110. * })
  111. *
  112. * assert.deepStrictEqual(M.concat({ x: 1, y: 2 }, { x: 3, y: 4 }), { x: 4, y: 6 })
  113. *
  114. * @since 2.10.0
  115. */
  116. var struct = function (monoids) {
  117. var empty = {};
  118. for (var k in monoids) {
  119. if (_.has.call(monoids, k)) {
  120. empty[k] = monoids[k].empty;
  121. }
  122. }
  123. return {
  124. concat: Se.struct(monoids).concat,
  125. empty: empty
  126. };
  127. };
  128. exports.struct = struct;
  129. /**
  130. * Given a tuple of monoids returns a monoid for the tuple.
  131. *
  132. * @example
  133. * import { tuple } from 'fp-ts/Monoid'
  134. * import * as B from 'fp-ts/boolean'
  135. * import * as N from 'fp-ts/number'
  136. * import * as S from 'fp-ts/string'
  137. *
  138. * const M1 = tuple(S.Monoid, N.MonoidSum)
  139. * assert.deepStrictEqual(M1.concat(['a', 1], ['b', 2]), ['ab', 3])
  140. *
  141. * const M2 = tuple(S.Monoid, N.MonoidSum, B.MonoidAll)
  142. * assert.deepStrictEqual(M2.concat(['a', 1, true], ['b', 2, false]), ['ab', 3, false])
  143. *
  144. * @since 2.10.0
  145. */
  146. var tuple = function () {
  147. var monoids = [];
  148. for (var _i = 0; _i < arguments.length; _i++) {
  149. monoids[_i] = arguments[_i];
  150. }
  151. return ({
  152. concat: Se.tuple.apply(Se, monoids).concat,
  153. empty: monoids.map(function (m) { return m.empty; })
  154. });
  155. };
  156. exports.tuple = tuple;
  157. // -------------------------------------------------------------------------------------
  158. // utils
  159. // -------------------------------------------------------------------------------------
  160. /**
  161. * Given a sequence of `as`, concat them and return the total.
  162. *
  163. * If `as` is empty, return the monoid `empty` value.
  164. *
  165. * @example
  166. * import { concatAll } from 'fp-ts/Monoid'
  167. * import * as N from 'fp-ts/number'
  168. *
  169. * assert.deepStrictEqual(concatAll(N.MonoidSum)([1, 2, 3]), 6)
  170. * assert.deepStrictEqual(concatAll(N.MonoidSum)([]), 0)
  171. *
  172. * @since 2.10.0
  173. */
  174. var concatAll = function (M) { return Se.concatAll(M)(M.empty); };
  175. exports.concatAll = concatAll;
  176. // -------------------------------------------------------------------------------------
  177. // deprecated
  178. // -------------------------------------------------------------------------------------
  179. /**
  180. * Use [`Monoid`](./void.ts.html#monoid) instead.
  181. *
  182. * @category zone of death
  183. * @since 2.0.0
  184. * @deprecated
  185. */
  186. exports.monoidVoid = {
  187. concat: Se.semigroupVoid.concat,
  188. empty: undefined
  189. };
  190. /**
  191. * Use [`tuple`](#tuple) instead.
  192. *
  193. * @category zone of death
  194. * @since 2.0.0
  195. * @deprecated
  196. */
  197. exports.getTupleMonoid = exports.tuple;
  198. /**
  199. * Use [`struct`](#struct) instead.
  200. *
  201. * @category zone of death
  202. * @since 2.0.0
  203. * @deprecated
  204. */
  205. exports.getStructMonoid = exports.struct;
  206. /**
  207. * Use [`reverse`](#reverse) instead.
  208. *
  209. * @category zone of death
  210. * @since 2.0.0
  211. * @deprecated
  212. */
  213. exports.getDualMonoid = exports.reverse;
  214. /**
  215. * Use [`max`](#max) instead.
  216. *
  217. * @category zone of death
  218. * @since 2.0.0
  219. * @deprecated
  220. */
  221. exports.getJoinMonoid = exports.max;
  222. /**
  223. * Use [`min`](#min) instead.
  224. *
  225. * @category zone of death
  226. * @since 2.0.0
  227. * @deprecated
  228. */
  229. exports.getMeetMonoid = exports.min;
  230. /**
  231. * Use [`concatAll`](#concatall) instead.
  232. *
  233. * @category zone of death
  234. * @since 2.0.0
  235. * @deprecated
  236. */
  237. exports.fold = exports.concatAll;
  238. /**
  239. * Use [`MonoidAll`](./boolean.ts.html#monoidall) instead.
  240. *
  241. * @category zone of death
  242. * @since 2.0.0
  243. * @deprecated
  244. */
  245. exports.monoidAll = {
  246. concat: Se.semigroupAll.concat,
  247. empty: true
  248. };
  249. /**
  250. * Use [`MonoidAny`](./boolean.ts.html#monoidany) instead.
  251. *
  252. * @category zone of death
  253. * @since 2.0.0
  254. * @deprecated
  255. */
  256. exports.monoidAny = {
  257. concat: Se.semigroupAny.concat,
  258. empty: false
  259. };
  260. /**
  261. * Use [`getMonoid`](./function.ts.html#getmonoid) instead.
  262. *
  263. * @category zone of death
  264. * @since 2.0.0
  265. * @deprecated
  266. */
  267. exports.getFunctionMonoid = function_1.getMonoid;
  268. /**
  269. * Use [`getEndomorphismMonoid`](./function.ts.html#getendomorphismmonoid) instead.
  270. *
  271. * **Note**. The execution order in [`getEndomorphismMonoid`](./function.ts.html#getendomorphismmonoid) is reversed.
  272. *
  273. * @category zone of death
  274. * @since 2.0.0
  275. * @deprecated
  276. */
  277. var getEndomorphismMonoid = function () { return (0, exports.reverse)((0, Endomorphism_1.getMonoid)()); };
  278. exports.getEndomorphismMonoid = getEndomorphismMonoid;
  279. /**
  280. * Use [`Monoid`](./string.ts.html#monoid) instead.
  281. *
  282. * @category zone of death
  283. * @since 2.0.0
  284. * @deprecated
  285. */
  286. exports.monoidString = {
  287. concat: Se.semigroupString.concat,
  288. empty: ''
  289. };
  290. /**
  291. * Use [`MonoidSum`](./number.ts.html#monoidsum) instead.
  292. *
  293. * @category zone of death
  294. * @since 2.0.0
  295. * @deprecated
  296. */
  297. exports.monoidSum = {
  298. concat: Se.semigroupSum.concat,
  299. empty: 0
  300. };
  301. /**
  302. * Use [`MonoidProduct`](./number.ts.html#monoidproduct) instead.
  303. *
  304. * @category zone of death
  305. * @since 2.0.0
  306. * @deprecated
  307. */
  308. exports.monoidProduct = {
  309. concat: Se.semigroupProduct.concat,
  310. empty: 1
  311. };