版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

47 righe
1.0 KiB

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