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

45 строки
1.4 KiB

  1. /**
  2. * A `Functor` is a type constructor which supports a mapping operation `map`.
  3. *
  4. * `map` can be used to turn functions `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.map(fa, a => a) <-> fa`
  10. * 2. Composition: `F.map(fa, a => bc(ab(a))) <-> F.map(F.map(fa, ab), bc)`
  11. *
  12. * @since 2.0.0
  13. */
  14. import { pipe } from './function';
  15. export function map(F, G) {
  16. return function (f) { return function (fa) { return F.map(fa, function (ga) { return G.map(ga, f); }); }; };
  17. }
  18. export function flap(F) {
  19. return function (a) { return function (fab) { return F.map(fab, function (f) { return f(a); }); }; };
  20. }
  21. export function bindTo(F) {
  22. return function (name) { return function (fa) { return F.map(fa, function (a) {
  23. var _a;
  24. return (_a = {}, _a[name] = a, _a);
  25. }); }; };
  26. }
  27. function let_(F) {
  28. return function (name, f) { return function (fa) { return F.map(fa, function (a) {
  29. var _a;
  30. return Object.assign({}, a, (_a = {}, _a[name] = f(a), _a));
  31. }); }; };
  32. }
  33. export {
  34. /**
  35. * @since 2.13.0
  36. */
  37. let_ as let };
  38. /** @deprecated */
  39. export function getFunctorComposition(F, G) {
  40. var _map = map(F, G);
  41. return {
  42. map: function (fga, f) { return pipe(fga, _map(f)); }
  43. };
  44. }