版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

94 řádky
2.2 KiB

  1. import { flap as flap_ } from './Functor';
  2. import { pipe } from './function';
  3. // TODO: curry in v3
  4. /**
  5. * Extracts a value at a relative position which depends on the current value.
  6. *
  7. * @since 2.0.0
  8. */
  9. export function tracks(M, f) {
  10. return function (wa) { return wa(f(wa(M.empty))); };
  11. }
  12. /**
  13. * Get the current position
  14. *
  15. * @since 2.0.0
  16. */
  17. export function listen(wa) {
  18. return function (e) { return [wa(e), e]; };
  19. }
  20. /**
  21. * Get a value which depends on the current position
  22. *
  23. * @since 2.0.0
  24. */
  25. export function listens(f) {
  26. return function (wa) { return function (e) { return [wa(e), f(e)]; }; };
  27. }
  28. /**
  29. * Apply a function to the current position
  30. *
  31. * @since 2.0.0
  32. */
  33. export function censor(f) {
  34. return function (wa) { return function (e) { return wa(f(e)); }; };
  35. }
  36. /**
  37. * @category instances
  38. * @since 2.0.0
  39. */
  40. export function getComonad(monoid) {
  41. function extend(wa, f) {
  42. return function (p1) { return f(function (p2) { return wa(monoid.concat(p1, p2)); }); };
  43. }
  44. function extract(wa) {
  45. return wa(monoid.empty);
  46. }
  47. return {
  48. URI: URI,
  49. _E: undefined,
  50. map: _map,
  51. extend: extend,
  52. extract: extract
  53. };
  54. }
  55. /* istanbul ignore next */
  56. var _map = function (fa, f) { return pipe(fa, map(f)); };
  57. /**
  58. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  59. * use the type constructor `F` to represent some computational context.
  60. *
  61. * @category mapping
  62. * @since 2.0.0
  63. */
  64. export var map = function (f) { return function (fa) { return function (p) { return f(fa(p)); }; }; };
  65. /**
  66. * @category type lambdas
  67. * @since 2.0.0
  68. */
  69. export var URI = 'Traced';
  70. /**
  71. * @category instances
  72. * @since 2.7.0
  73. */
  74. export var Functor = {
  75. URI: URI,
  76. map: _map
  77. };
  78. /**
  79. * @category mapping
  80. * @since 2.10.0
  81. */
  82. export var flap = /*#__PURE__*/ flap_(Functor);
  83. // -------------------------------------------------------------------------------------
  84. // deprecated
  85. // -------------------------------------------------------------------------------------
  86. /**
  87. * Use [`Functor`](#functor) instead.
  88. *
  89. * @category zone of death
  90. * @since 2.0.0
  91. * @deprecated
  92. */
  93. export var traced = Functor;