版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

40 wiersze
1.5 KiB

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