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

51 строка
1.2 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.newIORef = exports.IORef = void 0;
  4. /**
  5. * @example
  6. * import { io } from 'fp-ts/IO'
  7. * import { newIORef } from 'fp-ts/IORef'
  8. *
  9. * assert.strictEqual(io.chain(newIORef(1), ref => io.chain(ref.write(2), () => ref.read))(), 2)
  10. *
  11. * @category model
  12. * @since 2.0.0
  13. */
  14. var IORef = /** @class */ (function () {
  15. function IORef(value) {
  16. var _this = this;
  17. this.value = value;
  18. this.read = function () { return _this.value; };
  19. this.write = this.write.bind(this);
  20. this.modify = this.modify.bind(this);
  21. }
  22. /**
  23. * @since 2.0.0
  24. */
  25. IORef.prototype.write = function (a) {
  26. var _this = this;
  27. return function () {
  28. _this.value = a;
  29. };
  30. };
  31. /**
  32. * @since 2.0.0
  33. */
  34. IORef.prototype.modify = function (f) {
  35. var _this = this;
  36. return function () {
  37. _this.value = f(_this.value);
  38. };
  39. };
  40. return IORef;
  41. }());
  42. exports.IORef = IORef;
  43. /**
  44. * @category constructors
  45. * @since 2.0.0
  46. */
  47. function newIORef(a) {
  48. return function () { return new IORef(a); };
  49. }
  50. exports.newIORef = newIORef;