版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

Functor.js 1.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getFunctorComposition = exports.let = exports.bindTo = exports.flap = exports.map = void 0;
  4. /**
  5. * A `Functor` is a type constructor which supports a mapping operation `map`.
  6. *
  7. * `map` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return types use the type
  8. * constructor `f` to represent some computational context.
  9. *
  10. * Instances must satisfy the following laws:
  11. *
  12. * 1. Identity: `F.map(fa, a => a) <-> fa`
  13. * 2. Composition: `F.map(fa, a => bc(ab(a))) <-> F.map(F.map(fa, ab), bc)`
  14. *
  15. * @since 2.0.0
  16. */
  17. var function_1 = require("./function");
  18. function map(F, G) {
  19. return function (f) { return function (fa) { return F.map(fa, function (ga) { return G.map(ga, f); }); }; };
  20. }
  21. exports.map = map;
  22. function flap(F) {
  23. return function (a) { return function (fab) { return F.map(fab, function (f) { return f(a); }); }; };
  24. }
  25. exports.flap = flap;
  26. function bindTo(F) {
  27. return function (name) { return function (fa) { return F.map(fa, function (a) {
  28. var _a;
  29. return (_a = {}, _a[name] = a, _a);
  30. }); }; };
  31. }
  32. exports.bindTo = bindTo;
  33. function let_(F) {
  34. return function (name, f) { return function (fa) { return F.map(fa, function (a) {
  35. var _a;
  36. return Object.assign({}, a, (_a = {}, _a[name] = f(a), _a));
  37. }); }; };
  38. }
  39. exports.let = let_;
  40. /** @deprecated */
  41. function getFunctorComposition(F, G) {
  42. var _map = map(F, G);
  43. return {
  44. map: function (fga, f) { return (0, function_1.pipe)(fga, _map(f)); }
  45. };
  46. }
  47. exports.getFunctorComposition = getFunctorComposition;