@fp-ts/data
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -18,2 +18,47 @@ /** | ||
readonly _T: (_: never) => T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
get<T>(this: MutableRef<T>): T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
set<T>(this: MutableRef<T>, value: T): MutableRef<T>; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
update<T>(this: MutableRef<T>, f: (value: T) => T): MutableRef<T>; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
updateAndGet<T>(this: MutableRef<T>, f: (value: T) => T): T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
getAndUpdate<T>(this: MutableRef<T>, f: (value: T) => T): T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
setAndGet<T>(this: MutableRef<T>, value: T): T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
getAndSet<T>(this: MutableRef<T>, value: T): T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
compareAndSet<T>(this: MutableRef<T>, oldValue: T, newValue: T): boolean; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
pipe<T, B>(this: MutableRef<T>, f: (_: MutableRef<T>) => B): B; | ||
} | ||
@@ -27,5 +72,5 @@ /** | ||
* @since 1.0.0 | ||
* @category constructors | ||
* @category general | ||
*/ | ||
export declare const MutableRef: <T>(value: T) => MutableRef<T>; | ||
export declare const get: <T>(self: MutableRef<T>) => T; | ||
/** | ||
@@ -35,3 +80,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const get: <T>(self: MutableRef<T>) => T; | ||
export declare const set: <T>(value: T) => (self: MutableRef<T>) => MutableRef<T>; | ||
/** | ||
@@ -41,3 +86,3 @@ * @since 1.0.0 | ||
*/ | ||
export declare const set: <T>(value: T) => (self: MutableRef<T>) => MutableRef<T>; | ||
export declare const update: <T>(f: (value: T) => T) => (self: MutableRef<T>) => MutableRef<T>; | ||
/** | ||
@@ -47,2 +92,12 @@ * @since 1.0.0 | ||
*/ | ||
export declare const updateAndGet: <T>(f: (value: T) => T) => (self: MutableRef<T>) => T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
export declare const getAndUpdate: <T>(f: (value: T) => T) => (self: MutableRef<T>) => T; | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
export declare const setAndGet: <T>(value: T) => (self: MutableRef<T>) => T; | ||
@@ -73,2 +128,7 @@ /** | ||
*/ | ||
export declare const increment: (self: MutableRef<number>) => MutableRef<number>; | ||
/** | ||
* @since 1.0.0 | ||
* @category numeric | ||
*/ | ||
export declare const decrementAndGet: (self: MutableRef<number>) => number; | ||
@@ -80,3 +140,13 @@ /** | ||
export declare const getAndDecrement: (self: MutableRef<number>) => number; | ||
/** | ||
* @since 1.0.0 | ||
* @category numeric | ||
*/ | ||
export declare const decrement: (self: MutableRef<number>) => MutableRef<number>; | ||
/** | ||
* @since 1.0.0 | ||
* @category boolean | ||
*/ | ||
export declare const toggle: (self: MutableRef<boolean>) => MutableRef<boolean>; | ||
export {}; | ||
//# sourceMappingURL=MutableRef.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.setAndGet = exports.set = exports.make = exports.incrementAndGet = exports.getAndSet = exports.getAndIncrement = exports.getAndDecrement = exports.get = exports.decrementAndGet = exports.compareAndSet = exports.MutableRef = void 0; | ||
exports.updateAndGet = exports.update = exports.toggle = exports.setAndGet = exports.set = exports.make = exports.incrementAndGet = exports.increment = exports.getAndUpdate = exports.getAndSet = exports.getAndIncrement = exports.getAndDecrement = exports.get = exports.decrementAndGet = exports.decrement = exports.compareAndSet = void 0; | ||
@@ -37,2 +37,47 @@ var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/data/Equal")); | ||
get() { | ||
return this.current; | ||
} | ||
set(value) { | ||
this.current = value; | ||
return this; | ||
} | ||
setAndGet(value) { | ||
this.current = value; | ||
return this.current; | ||
} | ||
getAndSet(value) { | ||
const ret = this.current; | ||
this.current = value; | ||
return ret; | ||
} | ||
compareAndSet(oldValue, newValue) { | ||
if (Equal.equals(oldValue, this.current)) { | ||
this.current = newValue; | ||
return true; | ||
} | ||
return false; | ||
} | ||
pipe(f) { | ||
return f(this); | ||
} | ||
update(f) { | ||
return this.set(f(this.get())); | ||
} | ||
updateAndGet(f) { | ||
return this.setAndGet(f(this.get())); | ||
} | ||
getAndUpdate(f) { | ||
return this.getAndSet(f(this.get())); | ||
} | ||
} | ||
@@ -48,3 +93,3 @@ /** | ||
* @since 1.0.0 | ||
* @category constructors | ||
* @category general | ||
*/ | ||
@@ -55,3 +100,3 @@ | ||
const MutableRef = value => new MutableRefImpl(value); | ||
const get = self => self.current; | ||
/** | ||
@@ -63,5 +108,5 @@ * @since 1.0.0 | ||
exports.MutableRef = MutableRef; | ||
exports.get = get; | ||
const get = self => self.current; | ||
const set = value => self => self.set(value); | ||
/** | ||
@@ -73,5 +118,5 @@ * @since 1.0.0 | ||
exports.get = get; | ||
exports.set = set; | ||
const set = value => self => (self.current = value, self); | ||
const update = f => self => self.update(f); | ||
/** | ||
@@ -83,5 +128,5 @@ * @since 1.0.0 | ||
exports.set = set; | ||
exports.update = update; | ||
const setAndGet = value => self => (self.current = value, self.current); | ||
const updateAndGet = f => self => self.updateAndGet(f); | ||
/** | ||
@@ -93,9 +138,23 @@ * @since 1.0.0 | ||
exports.updateAndGet = updateAndGet; | ||
const getAndUpdate = f => self => self.getAndUpdate(f); | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
exports.getAndUpdate = getAndUpdate; | ||
const setAndGet = value => self => self.setAndGet(value); | ||
/** | ||
* @since 1.0.0 | ||
* @category general | ||
*/ | ||
exports.setAndGet = setAndGet; | ||
const getAndSet = value => self => { | ||
const current = self.current; | ||
self.current = value; | ||
return current; | ||
}; | ||
const getAndSet = value => self => self.getAndSet(value); | ||
/** | ||
@@ -109,10 +168,3 @@ * @since 1.0.0 | ||
const compareAndSet = (oldValue, newValue) => self => { | ||
if (Equal.equals(oldValue, self.current)) { | ||
self.current = newValue; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
const compareAndSet = (oldValue, newValue) => self => self.compareAndSet(oldValue, newValue); | ||
/** | ||
@@ -126,6 +178,3 @@ * @since 1.0.0 | ||
const incrementAndGet = self => { | ||
self.current = self.current + 1; | ||
return self.current; | ||
}; | ||
const incrementAndGet = self => self.updateAndGet(_ => _ + 1); | ||
/** | ||
@@ -139,7 +188,3 @@ * @since 1.0.0 | ||
const getAndIncrement = self => { | ||
const current = self.current; | ||
self.current = self.current + 1; | ||
return current; | ||
}; | ||
const getAndIncrement = self => self.getAndUpdate(_ => _ + 1); | ||
/** | ||
@@ -153,6 +198,3 @@ * @since 1.0.0 | ||
const decrementAndGet = self => { | ||
self.current = self.current - 1; | ||
return self.current; | ||
}; | ||
const increment = self => self.update(_ => _ + 1); | ||
/** | ||
@@ -164,11 +206,34 @@ * @since 1.0.0 | ||
exports.increment = increment; | ||
const decrementAndGet = self => self.updateAndGet(_ => _ - 1); | ||
/** | ||
* @since 1.0.0 | ||
* @category numeric | ||
*/ | ||
exports.decrementAndGet = decrementAndGet; | ||
const getAndDecrement = self => { | ||
const current = self.current; | ||
self.current = self.current + 1; | ||
return current; | ||
}; | ||
const getAndDecrement = self => self.getAndUpdate(_ => _ - 1); | ||
/** | ||
* @since 1.0.0 | ||
* @category numeric | ||
*/ | ||
exports.getAndDecrement = getAndDecrement; | ||
const decrement = self => self.update(_ => _ - 1); | ||
/** | ||
* @since 1.0.0 | ||
* @category boolean | ||
*/ | ||
exports.decrement = decrement; | ||
const toggle = self => self.update(_ => !_); | ||
exports.toggle = toggle; | ||
//# sourceMappingURL=MutableRef.js.map |
{ | ||
"name": "@fp-ts/data", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2159372
41651