版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

33 строки
1.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getFunctorWithIndexComposition = exports.mapWithIndex = void 0;
  4. /**
  5. * A `FunctorWithIndex` is a type constructor which supports a mapping operation `mapWithIndex`.
  6. *
  7. * `mapWithIndex` can be used to turn functions `i -> 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.mapWithIndex(fa, (_i, a) => a) <-> fa`
  13. * 2. Composition: `F.mapWithIndex(fa, (_i, a) => bc(ab(a))) <-> F.mapWithIndex(F.mapWithIndex(fa, ab), bc)`
  14. *
  15. * @since 2.0.0
  16. */
  17. var function_1 = require("./function");
  18. var Functor_1 = require("./Functor");
  19. function mapWithIndex(F, G) {
  20. return function (f) { return function (fa) { return F.mapWithIndex(fa, function (i, ga) { return G.mapWithIndex(ga, function (j, a) { return f([i, j], a); }); }); }; };
  21. }
  22. exports.mapWithIndex = mapWithIndex;
  23. /** @deprecated */
  24. function getFunctorWithIndexComposition(F, G) {
  25. var map = (0, Functor_1.getFunctorComposition)(F, G).map;
  26. var _mapWithIndex = mapWithIndex(F, G);
  27. return {
  28. map: map,
  29. mapWithIndex: function (fga, f) { return (0, function_1.pipe)(fga, _mapWithIndex(f)); }
  30. };
  31. }
  32. exports.getFunctorWithIndexComposition = getFunctorWithIndexComposition;