版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.store = exports.Comonad = exports.flap = exports.Functor = exports.URI = exports.map = exports.duplicate = exports.extract = exports.extend = exports.experiment = exports.peeks = exports.seeks = exports.seek = void 0;
  4. var function_1 = require("./function");
  5. var Functor_1 = require("./Functor");
  6. /**
  7. * Reposition the focus at the specified position
  8. *
  9. * @since 2.0.0
  10. */
  11. function seek(s) {
  12. return function (wa) { return ({ peek: wa.peek, pos: s }); };
  13. }
  14. exports.seek = seek;
  15. /**
  16. * Reposition the focus at the specified position, which depends on the current position
  17. *
  18. * @since 2.0.0
  19. */
  20. function seeks(f) {
  21. return function (wa) { return ({ peek: wa.peek, pos: f(wa.pos) }); };
  22. }
  23. exports.seeks = seeks;
  24. /**
  25. * Extract a value from a position which depends on the current position
  26. *
  27. * @since 2.0.0
  28. */
  29. function peeks(f) {
  30. return function (wa) { return wa.peek(f(wa.pos)); };
  31. }
  32. exports.peeks = peeks;
  33. function experiment(F) {
  34. return function (f) { return function (wa) { return F.map(f(wa.pos), function (s) { return wa.peek(s); }); }; };
  35. }
  36. exports.experiment = experiment;
  37. /* istanbul ignore next */
  38. var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
  39. /* istanbul ignore next */
  40. var _extend = function (wa, f) { return (0, function_1.pipe)(wa, (0, exports.extend)(f)); };
  41. /**
  42. * @since 2.0.0
  43. */
  44. var extend = function (f) { return function (wa) { return ({
  45. peek: function (s) { return f({ peek: wa.peek, pos: s }); },
  46. pos: wa.pos
  47. }); }; };
  48. exports.extend = extend;
  49. /**
  50. * @category Extract
  51. * @since 2.6.2
  52. */
  53. var extract = function (wa) { return wa.peek(wa.pos); };
  54. exports.extract = extract;
  55. /**
  56. * @since 2.0.0
  57. */
  58. exports.duplicate = (0, exports.extend)(function_1.identity);
  59. /**
  60. * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
  61. * use the type constructor `F` to represent some computational context.
  62. *
  63. * @category mapping
  64. * @since 2.0.0
  65. */
  66. var map = function (f) { return function (fa) { return ({
  67. peek: function (s) { return f(fa.peek(s)); },
  68. pos: fa.pos
  69. }); }; };
  70. exports.map = map;
  71. /**
  72. * @category type lambdas
  73. * @since 2.0.0
  74. */
  75. exports.URI = 'Store';
  76. /**
  77. * @category instances
  78. * @since 2.7.0
  79. */
  80. exports.Functor = {
  81. URI: exports.URI,
  82. map: _map
  83. };
  84. /**
  85. * @category mapping
  86. * @since 2.10.0
  87. */
  88. exports.flap = (0, Functor_1.flap)(exports.Functor);
  89. /**
  90. * @category instances
  91. * @since 2.7.0
  92. */
  93. exports.Comonad = {
  94. URI: exports.URI,
  95. map: _map,
  96. extend: _extend,
  97. extract: exports.extract
  98. };
  99. // -------------------------------------------------------------------------------------
  100. // deprecated
  101. // -------------------------------------------------------------------------------------
  102. /**
  103. * This instance is deprecated, use small, specific instances instead.
  104. * For example if a function needs a `Comonad` instance, pass `S.Comonad` instead of `S.store`
  105. * (where `S` is from `import S from 'fp-ts/Store'`)
  106. *
  107. * @category zone of death
  108. * @since 2.0.0
  109. * @deprecated
  110. */
  111. exports.store = exports.Comonad;