Innovenergy_trunk/frontend/node_modules/fp-ts/es6/IORef.js

47 lines
1.0 KiB
JavaScript

/**
* @example
* import { io } from 'fp-ts/IO'
* import { newIORef } from 'fp-ts/IORef'
*
* assert.strictEqual(io.chain(newIORef(1), ref => io.chain(ref.write(2), () => ref.read))(), 2)
*
* @category model
* @since 2.0.0
*/
var IORef = /** @class */ (function () {
function IORef(value) {
var _this = this;
this.value = value;
this.read = function () { return _this.value; };
this.write = this.write.bind(this);
this.modify = this.modify.bind(this);
}
/**
* @since 2.0.0
*/
IORef.prototype.write = function (a) {
var _this = this;
return function () {
_this.value = a;
};
};
/**
* @since 2.0.0
*/
IORef.prototype.modify = function (f) {
var _this = this;
return function () {
_this.value = f(_this.value);
};
};
return IORef;
}());
export { IORef };
/**
* @category constructors
* @since 2.0.0
*/
export function newIORef(a) {
return function () { return new IORef(a); };
}