@parischap/effect-lib
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -111,3 +111,3 @@ "use strict"; | ||
const key = fKey(a); | ||
// eslint-disable-next-line functional/immutable-data,functional/no-expression-statements,functional/prefer-readonly-type | ||
/* eslint-disable-next-line functional/immutable-data,functional/no-expression-statements,functional/prefer-readonly-type */ | ||
if (key >= 0 && key < size) out[key].push(fValue(a)); | ||
@@ -114,0 +114,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.makeValueContainer = exports.make = exports.get = void 0; | ||
exports.makeValueContainer = exports.make = exports.keysInStore = exports.get = void 0; | ||
var _effect = /*#__PURE__*/require("effect"); | ||
@@ -35,4 +35,7 @@ var MTypes = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./types.js")); | ||
} | ||
/* eslint functional/no-expression-statements: "off" */ | ||
/** | ||
* This module implements a cache with a fixed capacity and time-to-live. The contents of the cache is populated by a lookup function which may be recursive. The cache capacity may temporarily be exceeded if the lookup function is recursive (because the cache is also used to determine circularity). Keys are compared using Equal.equals. | ||
*/ | ||
const moduleTag = '@parischap/effect-lib/Cache/'; | ||
/** | ||
@@ -48,4 +51,6 @@ * @category models | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.value = value; | ||
this.storeDate = storeDate; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -78,3 +83,3 @@ [_effect.Equal.symbol](that) { | ||
/** | ||
* The key/value cache. A None means the value is currently nder calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
* The key/value cache. A None value means the value is currently under calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
*/ | ||
@@ -91,3 +96,3 @@ store; | ||
/** | ||
* The capicity ofthe cache. If undefined, the cache is unbounded | ||
* The capicity of the cache. If undefined, the cache is unbounded | ||
*/ | ||
@@ -104,2 +109,3 @@ capacity; | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.store = _effect.MutableHashMap.empty(); | ||
@@ -110,3 +116,19 @@ this.keyOrder = _effect.MutableQueue.unbounded(); | ||
this.lifeSpan = lifeSpan; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
toJSON() { | ||
return { | ||
_id: moduleTag, | ||
store: _effect.Inspectable.toJSON(this.store), | ||
keyOrder: _effect.Inspectable.toJSON(this.keyOrder), | ||
capacity: _effect.Inspectable.toJSON(this.capacity), | ||
lifeSpan: _effect.Inspectable.toJSON(this.lifeSpan) | ||
}; | ||
} | ||
[_effect.Inspectable.NodeInspectSymbol]() { | ||
return this.toJSON(); | ||
} | ||
toString() { | ||
return _effect.Inspectable.format(this.toJSON()); | ||
} | ||
} | ||
@@ -132,2 +154,3 @@ /** | ||
onNone: () => { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.set(store, a, _effect.Option.none()); | ||
@@ -140,2 +163,3 @@ const [result, storeInCache] = self.lookUp({ | ||
if (storeInCache) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.set(store, a, _effect.Option.some(makeValueContainer({ | ||
@@ -146,7 +170,10 @@ value: result, | ||
if (self.capacity !== undefined) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableQueue.offer(keyOrder, a); | ||
if (_effect.MutableQueue.length(keyOrder) > self.capacity) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.remove(store, _effect.MutableQueue.poll(keyOrder, _effect.MutableQueue.EmptyMutableQueue)); | ||
} | ||
} | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
} else _effect.MutableHashMap.remove(store, a); | ||
@@ -162,10 +189,15 @@ return result; | ||
onSome: valueContainer => { | ||
if (self.lifeSpan !== undefined && now - valueContainer.storeDate > self.lifeSpan) { | ||
if (self.lifeSpan !== undefined && ( | ||
// if lifespan===0, we don't do the test because it could return false if the two values are stored in the same millisecond. | ||
self.lifeSpan === 0 || now - valueContainer.storeDate > self.lifeSpan)) { | ||
if (self.capacity !== undefined) { | ||
let head = _effect.MutableQueue.poll(keyOrder, _effect.MutableQueue.EmptyMutableQueue); | ||
while (!_effect.Equal.equals(a, head)) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.remove(store, head); | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
head = _effect.MutableQueue.poll(keyOrder, _effect.MutableQueue.EmptyMutableQueue); | ||
} | ||
} | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.set(store, a, _effect.Option.none()); | ||
@@ -178,2 +210,3 @@ const [result, storeInCache] = self.lookUp({ | ||
if (storeInCache) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableHashMap.set(store, a, _effect.Option.some(makeValueContainer({ | ||
@@ -183,3 +216,5 @@ value: result, | ||
}))); | ||
if (self.capacity !== undefined) _effect.MutableQueue.offer(keyOrder, a); | ||
if (self.capacity !== undefined) /* eslint-disable-next-line functional/no-expression-statements */ | ||
_effect.MutableQueue.offer(keyOrder, a); | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
} else _effect.MutableHashMap.remove(store, a); | ||
@@ -195,2 +230,4 @@ return result; | ||
exports.get = get; | ||
const keysInStore = self => (0, _effect.pipe)(self.store, _effect.Array.fromIterable, _effect.Array.filter((0, _effect.flow)(_effect.Tuple.getSecond, _effect.Option.isSome)), _effect.Array.map(_effect.Tuple.getFirst)); | ||
exports.keysInStore = keysInStore; | ||
//# sourceMappingURL=Cache.js.map |
@@ -62,3 +62,3 @@ "use strict"; | ||
const result = f(); | ||
// eslint-disable-next-line functional/no-expression-statements | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
store = _effect.Option.some(result); | ||
@@ -65,0 +65,0 @@ return result; |
@@ -51,2 +51,5 @@ "use strict"; | ||
result; | ||
/** | ||
* Rest represents the types that have not yet been checked for self | ||
*/ | ||
_rest; | ||
@@ -57,4 +60,6 @@ constructor({ | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.value = value; | ||
this.result = result; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -70,2 +75,3 @@ } | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, applies the predicate to the value of self. Returns a copy of self if the predicate returns 'false'. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -79,2 +85,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, the value of self is compared to a provided value using the Equal.equals operator. Returns a copy of self if the two values are not equal. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -88,2 +95,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, calls a function f with the value of self as parameter. Returns a copy of self if f returns a `none`. Otherwise, returns a copy of self with the result set to the output the f function (extracted from the `some`). | ||
* @category combinators | ||
@@ -97,2 +105,3 @@ */ | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if one of the predicate returns 'true'. | ||
* @category combinators | ||
@@ -105,2 +114,6 @@ */ | ||
}); | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if all the predicates return 'true'. | ||
* @category combinators | ||
*/ | ||
exports.whenOr = whenOr; | ||
@@ -112,23 +125,20 @@ const whenAnd = (...args) => self => new Type({ | ||
/** | ||
* Returns the result of self if self already has a result. Otherwise, returns the result of f applied to the value of self. | ||
* @category combinators | ||
*/ | ||
exports.whenAnd = whenAnd; | ||
const unsafeWhen = (_predicate, f) => self => _effect.Option.getOrElse(self.result, () => f(self.value)); | ||
const orElse = f => self => _effect.Option.getOrElse(self.result, () => f(self.value)); | ||
/** | ||
* Same as orElse but we pass a predicate (useless from a javascript perspective) tell the compiler what types have not been checked yet. Useful when we know better than Typescript. | ||
* @category combinators | ||
*/ | ||
exports.unsafeWhen = unsafeWhen; | ||
const orElse = f => self => _effect.Option.getOrElse(self.result, () => f(self.value)); | ||
exports.orElse = orElse; | ||
const unsafeWhen = (_predicate, f) => self => _effect.Option.getOrElse(self.result, () => f(self.value)); | ||
/** | ||
* Returns the result of the matcher and shows a type error if all type possibilities have not been tried | ||
* @category combinators | ||
*/ | ||
/*export const orElseThrow = <Input, Rest extends Input, Output>( | ||
self: Type<Input, Output, Rest> | ||
): Output => | ||
Option.getOrElse(self.result, () => { | ||
throw new Error('Abnormal error'); | ||
});*/ | ||
exports.orElse = orElse; | ||
exports.unsafeWhen = unsafeWhen; | ||
const exhaustive = self => self.result.value; | ||
exports.exhaustive = exhaustive; | ||
//# sourceMappingURL=Match.js.map |
@@ -46,5 +46,7 @@ "use strict"; | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.startIndex = startIndex; | ||
this.endIndex = endIndex; | ||
this.match = match; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -96,3 +98,3 @@ } | ||
const searchAll = regexp => self => { | ||
// eslint-disable-next-line functional/prefer-readonly-type -- To preserve refinements | ||
/* eslint-disable-next-line functional/prefer-readonly-type -- To preserve refinements */ | ||
const result = []; | ||
@@ -104,5 +106,5 @@ let searchPos = 0; | ||
const searchResult = searchResultOption.value; | ||
// eslint-disable-next-line functional/immutable-data,functional/no-expression-statements | ||
/* eslint-disable-next-line functional/immutable-data,functional/no-expression-statements */ | ||
result.push(searchResult); | ||
// eslint-disable-next-line functional/no-expression-statements | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
searchPos = searchResult.endIndex; | ||
@@ -152,4 +154,3 @@ } | ||
}; | ||
return (0, _effect.pipe)(obj['toString'], | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
return (0, _effect.pipe)(obj['toString'], /* eslint-disable-next-line @typescript-eslint/unbound-method */ | ||
_effect.Option.liftPredicate(_effect.Predicate.not(MFunction.strictEquals(Object.prototype.toString))), _effect.Option.flatMap(tryApplyingFOnObj), _effect.Option.orElse(() => (0, _effect.pipe)(obj['toJSON'], _effect.Option.liftPredicate(MTypes.isFunction), _effect.Option.flatMap(tryApplyingFOnObj)))); | ||
@@ -156,0 +157,0 @@ }; |
@@ -17,4 +17,3 @@ "use strict"; | ||
exports.make = make; | ||
const enrichWith = fields => self => (0, _effect.pipe)(fields, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
const enrichWith = fields => self => (0, _effect.pipe)(fields, /* eslint-disable-next-line @typescript-eslint/no-unsafe-return */ | ||
_effect.Record.map(f => f(self)), newValues => ({ | ||
@@ -21,0 +20,0 @@ ...self, |
@@ -1,6 +0,6 @@ | ||
import { Equal, Hash, Inspectable, MutableHashMap, MutableQueue, Option } from 'effect'; | ||
import * as MTypes from './types.js'; | ||
/** | ||
* This module implements a cache with a fixed capacity and time-to-live. The contents of the cache is populated by a lookup function which may be recursive. The cache capacity may temporarily be exceeded if the lookup function is recursive (because the cache is also used to determine circularity). Keys are compared using Equal.equals. | ||
*/ | ||
import { Equal, Hash, Inspectable, MutableHashMap, MutableQueue, Option } from 'effect'; | ||
import * as MTypes from './types.js'; | ||
/** | ||
@@ -46,5 +46,5 @@ * In addition to the key, the lookup function receives a memoized version of itself if it needs to perform recursion. It also receives a flag indicating whether circularity was detected. In that case, the memoized version of the function is not passed as recursion should be stopped to avoid an infinite loop. The output of the function must contain the result of the function and a boolean indicating whether the result should be stored in the cache. Note that when isCircular is true, the result is not stored in the cache even if the result of the function indicates it should. | ||
*/ | ||
declare class Type<in out A, in out B> { | ||
declare class Type<in out A, in out B> implements Inspectable.Inspectable { | ||
/** | ||
* The key/value cache. A None means the value is currently nder calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
* The key/value cache. A None value means the value is currently under calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
*/ | ||
@@ -61,3 +61,3 @@ readonly store: MutableHashMap.MutableHashMap<A, Option.Option<ValueContainer<B>>>; | ||
/** | ||
* The capicity ofthe cache. If undefined, the cache is unbounded | ||
* The capicity of the cache. If undefined, the cache is unbounded | ||
*/ | ||
@@ -74,2 +74,17 @@ readonly capacity: number | undefined; | ||
}); | ||
toJSON(): { | ||
_id: string; | ||
store: unknown; | ||
keyOrder: unknown; | ||
capacity: unknown; | ||
lifeSpan: unknown; | ||
}; | ||
[Inspectable.NodeInspectSymbol](): { | ||
_id: string; | ||
store: unknown; | ||
keyOrder: unknown; | ||
capacity: unknown; | ||
lifeSpan: unknown; | ||
}; | ||
toString(): string; | ||
} | ||
@@ -94,2 +109,3 @@ export { type Type }; | ||
export declare const get: <A>(a: A) => <B>(self: Type<A, B>) => B; | ||
export declare const keysInStore: <A, B>(self: Type<A, B>) => Array<A>; | ||
//# sourceMappingURL=Cache.d.ts.map |
@@ -19,2 +19,5 @@ /** | ||
readonly result: Option.Option<Output>; | ||
/** | ||
* Rest represents the types that have not yet been checked for self | ||
*/ | ||
readonly _rest?: Types.Covariant<Rest>; | ||
@@ -29,2 +32,3 @@ constructor({ value, result }: MTypes.Data<Type<Input, Output>>); | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, applies the predicate to the value of self. Returns a copy of self if the predicate returns 'false'. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -34,2 +38,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, the value of self is compared to a provided value using the Equal.equals operator. Returns a copy of self if the two values are not equal. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -39,2 +44,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, calls a function f with the value of self as parameter. Returns a copy of self if f returns a `none`. Otherwise, returns a copy of self with the result set to the output the f function (extracted from the `some`). | ||
* @category combinators | ||
@@ -44,11 +50,13 @@ */ | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if one of the predicate returns 'true'. | ||
* @category combinators | ||
*/ | ||
export declare const whenOr: <Input, Rest extends Input, R extends MTypes.OverTwo<Predicate.Predicate<Rest>>, Output1>(...args: readonly [...refinements: R, f: (value: NoInfer<MPredicate.PredicatesToTargets<R>[number] & Rest>) => Output1]) => <Output>(self: Type<Input, Output, Rest>) => Type<Input, Output | Output1, Exclude<Rest, MPredicate.PredicatesToDifferences<R>[number]>>; | ||
export declare const whenAnd: <Input, Rest extends Input, R extends MTypes.OverTwo<Predicate.Predicate<Rest>>, Output1>(...args: readonly [...refinements: R, f: (value: NoInfer<MTypes.TupleToIntersection<MPredicate.PredicatesToTargets<R>>> & Rest) => Output1]) => <Output>(self: Type<Input, Output, Rest>) => Type<Input, Output | Output1, Exclude<Rest, MTypes.TupleToIntersection<MPredicate.PredicatesToDifferences<R>>>>; | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if all the predicates return 'true'. | ||
* @category combinators | ||
*/ | ||
export declare const unsafeWhen: <Input, Rest extends Input, Refinement extends MTypes.RefinementFrom<Rest>, Output1>(_predicate: Refinement, f: (value: NoInfer<MPredicate.Target<Refinement>>) => Output1) => <Output>(self: Type<Input, Output, Rest>) => Output | Output1; | ||
export declare const whenAnd: <Input, Rest extends Input, R extends MTypes.OverTwo<Predicate.Predicate<Rest>>, Output1>(...args: readonly [...refinements: R, f: (value: NoInfer<MTypes.TupleToIntersection<MPredicate.PredicatesToTargets<R>>> & Rest) => Output1]) => <Output>(self: Type<Input, Output, Rest>) => Type<Input, Output | Output1, Exclude<Rest, MTypes.TupleToIntersection<MPredicate.PredicatesToDifferences<R>>>>; | ||
/** | ||
* Returns the result of self if self already has a result. Otherwise, returns the result of f applied to the value of self. | ||
* @category combinators | ||
@@ -58,5 +66,11 @@ */ | ||
/** | ||
* Same as orElse but we pass a predicate (useless from a javascript perspective) tell the compiler what types have not been checked yet. Useful when we know better than Typescript. | ||
* @category combinators | ||
*/ | ||
export declare const unsafeWhen: <Input, Rest extends Input, Refinement extends MTypes.RefinementFrom<Rest>, Output1>(_predicate: Refinement, f: (value: NoInfer<MPredicate.Target<Refinement>>) => Output1) => <Output>(self: Type<Input, Output, Rest>) => Output | Output1; | ||
/** | ||
* Returns the result of the matcher and shows a type error if all type possibilities have not been tried | ||
* @category combinators | ||
*/ | ||
export declare const exhaustive: <Input, Output>(self: Type<Input, Output, never>) => Output; | ||
//# sourceMappingURL=Match.d.ts.map |
@@ -70,3 +70,3 @@ import { Array, Equal, Option, Record, Tuple, pipe } from 'effect'; | ||
const key = fKey(a); | ||
// eslint-disable-next-line functional/immutable-data,functional/no-expression-statements,functional/prefer-readonly-type | ||
/* eslint-disable-next-line functional/immutable-data,functional/no-expression-statements,functional/prefer-readonly-type */ | ||
if (key >= 0 && key < size) out[key].push(fValue(a)); | ||
@@ -73,0 +73,0 @@ } |
@@ -1,4 +0,7 @@ | ||
/* eslint functional/no-expression-statements: "off" */ | ||
import { Equal, Hash, Inspectable, MutableHashMap, MutableQueue, Option, Tuple, pipe } from 'effect'; | ||
/** | ||
* This module implements a cache with a fixed capacity and time-to-live. The contents of the cache is populated by a lookup function which may be recursive. The cache capacity may temporarily be exceeded if the lookup function is recursive (because the cache is also used to determine circularity). Keys are compared using Equal.equals. | ||
*/ | ||
import { Array, Equal, Hash, Inspectable, MutableHashMap, MutableQueue, Option, Tuple, flow, pipe } from 'effect'; | ||
import * as MTypes from './types.js'; | ||
const moduleTag = '@parischap/effect-lib/Cache/'; | ||
/** | ||
@@ -14,4 +17,6 @@ * @category models | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.value = value; | ||
this.storeDate = storeDate; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -43,3 +48,3 @@ [Equal.symbol](that) { | ||
/** | ||
* The key/value cache. A None means the value is currently nder calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
* The key/value cache. A None value means the value is currently under calculation. A circular flag will be sent if the value needs to be retreived while it is being calculated. | ||
*/ | ||
@@ -56,3 +61,3 @@ store; | ||
/** | ||
* The capicity ofthe cache. If undefined, the cache is unbounded | ||
* The capicity of the cache. If undefined, the cache is unbounded | ||
*/ | ||
@@ -69,2 +74,3 @@ capacity; | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.store = MutableHashMap.empty(); | ||
@@ -75,3 +81,19 @@ this.keyOrder = MutableQueue.unbounded(); | ||
this.lifeSpan = lifeSpan; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
toJSON() { | ||
return { | ||
_id: moduleTag, | ||
store: Inspectable.toJSON(this.store), | ||
keyOrder: Inspectable.toJSON(this.keyOrder), | ||
capacity: Inspectable.toJSON(this.capacity), | ||
lifeSpan: Inspectable.toJSON(this.lifeSpan) | ||
}; | ||
} | ||
[Inspectable.NodeInspectSymbol]() { | ||
return this.toJSON(); | ||
} | ||
toString() { | ||
return Inspectable.format(this.toJSON()); | ||
} | ||
} | ||
@@ -96,2 +118,3 @@ /** | ||
onNone: () => { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.set(store, a, Option.none()); | ||
@@ -104,2 +127,3 @@ const [result, storeInCache] = self.lookUp({ | ||
if (storeInCache) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.set(store, a, Option.some(makeValueContainer({ | ||
@@ -110,7 +134,10 @@ value: result, | ||
if (self.capacity !== undefined) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableQueue.offer(keyOrder, a); | ||
if (MutableQueue.length(keyOrder) > self.capacity) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.remove(store, MutableQueue.poll(keyOrder, MutableQueue.EmptyMutableQueue)); | ||
} | ||
} | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
} else MutableHashMap.remove(store, a); | ||
@@ -126,10 +153,15 @@ return result; | ||
onSome: valueContainer => { | ||
if (self.lifeSpan !== undefined && now - valueContainer.storeDate > self.lifeSpan) { | ||
if (self.lifeSpan !== undefined && ( | ||
// if lifespan===0, we don't do the test because it could return false if the two values are stored in the same millisecond. | ||
self.lifeSpan === 0 || now - valueContainer.storeDate > self.lifeSpan)) { | ||
if (self.capacity !== undefined) { | ||
let head = MutableQueue.poll(keyOrder, MutableQueue.EmptyMutableQueue); | ||
while (!Equal.equals(a, head)) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.remove(store, head); | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
head = MutableQueue.poll(keyOrder, MutableQueue.EmptyMutableQueue); | ||
} | ||
} | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.set(store, a, Option.none()); | ||
@@ -142,2 +174,3 @@ const [result, storeInCache] = self.lookUp({ | ||
if (storeInCache) { | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableHashMap.set(store, a, Option.some(makeValueContainer({ | ||
@@ -147,3 +180,5 @@ value: result, | ||
}))); | ||
if (self.capacity !== undefined) MutableQueue.offer(keyOrder, a); | ||
if (self.capacity !== undefined) /* eslint-disable-next-line functional/no-expression-statements */ | ||
MutableQueue.offer(keyOrder, a); | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
} else MutableHashMap.remove(store, a); | ||
@@ -158,2 +193,3 @@ return result; | ||
}; | ||
export const keysInStore = self => pipe(self.store, Array.fromIterable, Array.filter(flow(Tuple.getSecond, Option.isSome)), Array.map(Tuple.getFirst)); | ||
//# sourceMappingURL=Cache.js.map |
@@ -50,3 +50,3 @@ import { Either, Equal, Option, pipe } from 'effect'; | ||
const result = f(); | ||
// eslint-disable-next-line functional/no-expression-statements | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
store = Option.some(result); | ||
@@ -53,0 +53,0 @@ return result; |
@@ -19,2 +19,5 @@ /** | ||
result; | ||
/** | ||
* Rest represents the types that have not yet been checked for self | ||
*/ | ||
_rest; | ||
@@ -25,4 +28,6 @@ constructor({ | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.value = value; | ||
this.result = result; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -38,2 +43,3 @@ } | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, applies the predicate to the value of self. Returns a copy of self if the predicate returns 'false'. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -46,2 +52,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, the value of self is compared to a provided value using the Equal.equals operator. Returns a copy of self if the two values are not equal. Otherwise, returns a copy of self with the result set to the output of a function f called with the value of self as parameter. | ||
* @category combinators | ||
@@ -54,2 +61,3 @@ */ | ||
/** | ||
* returns a copy of self if self already has a result. Otherwise, calls a function f with the value of self as parameter. Returns a copy of self if f returns a `none`. Otherwise, returns a copy of self with the result set to the output the f function (extracted from the `some`). | ||
* @category combinators | ||
@@ -62,2 +70,3 @@ */ | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if one of the predicate returns 'true'. | ||
* @category combinators | ||
@@ -69,2 +78,6 @@ */ | ||
}); | ||
/** | ||
* Same as when but several predicates can be provided. The match occurs if all the predicates return 'true'. | ||
* @category combinators | ||
*/ | ||
export const whenAnd = (...args) => self => new Type({ | ||
@@ -75,19 +88,16 @@ value: self.value, | ||
/** | ||
* Returns the result of self if self already has a result. Otherwise, returns the result of f applied to the value of self. | ||
* @category combinators | ||
*/ | ||
export const unsafeWhen = (_predicate, f) => self => Option.getOrElse(self.result, () => f(self.value)); | ||
export const orElse = f => self => Option.getOrElse(self.result, () => f(self.value)); | ||
/** | ||
* Same as orElse but we pass a predicate (useless from a javascript perspective) tell the compiler what types have not been checked yet. Useful when we know better than Typescript. | ||
* @category combinators | ||
*/ | ||
export const orElse = f => self => Option.getOrElse(self.result, () => f(self.value)); | ||
export const unsafeWhen = (_predicate, f) => self => Option.getOrElse(self.result, () => f(self.value)); | ||
/** | ||
* Returns the result of the matcher and shows a type error if all type possibilities have not been tried | ||
* @category combinators | ||
*/ | ||
/*export const orElseThrow = <Input, Rest extends Input, Output>( | ||
self: Type<Input, Output, Rest> | ||
): Output => | ||
Option.getOrElse(self.result, () => { | ||
throw new Error('Abnormal error'); | ||
});*/ | ||
export const exhaustive = self => self.result.value; | ||
//# sourceMappingURL=Match.js.map |
@@ -15,5 +15,7 @@ import { Array, Function, Option, Order, Predicate, String, Tuple, pipe } from 'effect'; | ||
}) { | ||
/* eslint-disable functional/no-expression-statements */ | ||
this.startIndex = startIndex; | ||
this.endIndex = endIndex; | ||
this.match = match; | ||
/* eslint-enable functional/no-expression-statements */ | ||
} | ||
@@ -62,3 +64,3 @@ } | ||
export const searchAll = regexp => self => { | ||
// eslint-disable-next-line functional/prefer-readonly-type -- To preserve refinements | ||
/* eslint-disable-next-line functional/prefer-readonly-type -- To preserve refinements */ | ||
const result = []; | ||
@@ -70,5 +72,5 @@ let searchPos = 0; | ||
const searchResult = searchResultOption.value; | ||
// eslint-disable-next-line functional/immutable-data,functional/no-expression-statements | ||
/* eslint-disable-next-line functional/immutable-data,functional/no-expression-statements */ | ||
result.push(searchResult); | ||
// eslint-disable-next-line functional/no-expression-statements | ||
/* eslint-disable-next-line functional/no-expression-statements */ | ||
searchPos = searchResult.endIndex; | ||
@@ -114,4 +116,3 @@ } | ||
}; | ||
return pipe(obj['toString'], | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
return pipe(obj['toString'], /* eslint-disable-next-line @typescript-eslint/unbound-method */ | ||
Option.liftPredicate(Predicate.not(MFunction.strictEquals(Object.prototype.toString))), Option.flatMap(tryApplyingFOnObj), Option.orElse(() => pipe(obj['toJSON'], Option.liftPredicate(MTypes.isFunction), Option.flatMap(tryApplyingFOnObj)))); | ||
@@ -118,0 +119,0 @@ }; |
@@ -9,4 +9,3 @@ import { Record, pipe } from 'effect'; | ||
}); | ||
export const enrichWith = fields => self => pipe(fields, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
export const enrichWith = fields => self => pipe(fields, /* eslint-disable-next-line @typescript-eslint/no-unsafe-return */ | ||
Record.map(f => f(self)), newValues => ({ | ||
@@ -13,0 +12,0 @@ ...self, |
@@ -16,5 +16,2 @@ { | ||
"exports": { | ||
"./public/*": { | ||
"require": "./public/*" | ||
}, | ||
".": { | ||
@@ -28,8 +25,8 @@ "types": "./dts/index.d.ts", | ||
"peerDependencies": { | ||
"@parischap/js-lib": "^0.0.1", | ||
"@parischap/js-lib": "^0.0.2", | ||
"effect": "^3.6.3" | ||
}, | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "./cjs/index.js", | ||
"types": "./dts/index.d.ts" | ||
} |
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
320065
4273