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

28 строки
1.1 KiB

  1. /**
  2. * A `FunctorWithIndex` is a type constructor which supports a mapping operation `mapWithIndex`.
  3. *
  4. * `mapWithIndex` can be used to turn functions `i -> a -> b` into functions `f a -> f b` whose argument and return types use the type
  5. * constructor `f` to represent some computational context.
  6. *
  7. * Instances must satisfy the following laws:
  8. *
  9. * 1. Identity: `F.mapWithIndex(fa, (_i, a) => a) <-> fa`
  10. * 2. Composition: `F.mapWithIndex(fa, (_i, a) => bc(ab(a))) <-> F.mapWithIndex(F.mapWithIndex(fa, ab), bc)`
  11. *
  12. * @since 2.0.0
  13. */
  14. import { pipe } from './function';
  15. import { getFunctorComposition } from './Functor';
  16. export function mapWithIndex(F, G) {
  17. 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); }); }); }; };
  18. }
  19. /** @deprecated */
  20. export function getFunctorWithIndexComposition(F, G) {
  21. var map = getFunctorComposition(F, G).map;
  22. var _mapWithIndex = mapWithIndex(F, G);
  23. return {
  24. map: map,
  25. mapWithIndex: function (fga, f) { return pipe(fga, _mapWithIndex(f)); }
  26. };
  27. }