版博士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 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getApplicativeComposition = exports.getApplicativeMonoid = void 0;
  4. /**
  5. * The `Applicative` type class extends the `Apply` type class with a `of` function, which can be used to create values
  6. * of type `f a` from values of type `a`.
  7. *
  8. * Where `Apply` provides the ability to lift functions of two or more arguments to functions whose arguments are
  9. * wrapped using `f`, and `Functor` provides the ability to lift functions of one argument, `pure` can be seen as the
  10. * function which lifts functions of _zero_ arguments. That is, `Applicative` functors support a lifting operation for
  11. * any number of function arguments.
  12. *
  13. * Instances must satisfy the following laws in addition to the `Apply` laws:
  14. *
  15. * 1. Identity: `A.ap(A.of(a => a), fa) <-> fa`
  16. * 2. Homomorphism: `A.ap(A.of(ab), A.of(a)) <-> A.of(ab(a))`
  17. * 3. Interchange: `A.ap(fab, A.of(a)) <-> A.ap(A.of(ab => ab(a)), fab)`
  18. *
  19. * Note. `Functor`'s `map` can be derived: `A.map(x, f) = A.ap(A.of(f), x)`
  20. *
  21. * @since 2.0.0
  22. */
  23. var Apply_1 = require("./Apply");
  24. var function_1 = require("./function");
  25. var Functor_1 = require("./Functor");
  26. function getApplicativeMonoid(F) {
  27. var f = (0, Apply_1.getApplySemigroup)(F);
  28. return function (M) { return ({
  29. concat: f(M).concat,
  30. empty: F.of(M.empty)
  31. }); };
  32. }
  33. exports.getApplicativeMonoid = getApplicativeMonoid;
  34. /** @deprecated */
  35. function getApplicativeComposition(F, G) {
  36. var map = (0, Functor_1.getFunctorComposition)(F, G).map;
  37. var _ap = (0, Apply_1.ap)(F, G);
  38. return {
  39. map: map,
  40. of: function (a) { return F.of(G.of(a)); },
  41. ap: function (fgab, fga) { return (0, function_1.pipe)(fgab, _ap(fga)); }
  42. };
  43. }
  44. exports.getApplicativeComposition = getApplicativeComposition;