Comparing version 0.0.734 to 0.0.735
@@ -19,7 +19,22 @@ import { isArray } from './alias'; | ||
if (typeof identify === 'object') return memoize(f, undefined, identify as Dict<b, z>); | ||
return isArray(memory) || memory?.constructor === Object | ||
? memoizeRecord(f, identify, memory as z[]) | ||
: memoizeDict(f, identify, memory as Dict<b, z> ?? new Map()); | ||
switch (true) { | ||
case isArray(memory): | ||
return memoizeArray(f, identify, memory as z[]); | ||
case memory?.constructor === Object: | ||
return memoizeObject(f, identify, memory as Record<number, z>); | ||
default: | ||
return memoizeDict(f, identify, memory as Dict<b, z> ?? new Map()); | ||
} | ||
} | ||
function memoizeRecord<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: Record<number, z>): typeof f { | ||
function memoizeArray<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: z[]): typeof f { | ||
return (...as) => { | ||
const b = identify(...as) as number; | ||
let z = memory[b]; | ||
if (z !== undefined) return z!; | ||
z = f(...as); | ||
memory[b] = z; | ||
return z; | ||
}; | ||
} | ||
function memoizeObject<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: Record<number, z>): typeof f { | ||
let nullable = false; | ||
@@ -29,3 +44,3 @@ return (...as) => { | ||
let z = memory[b]; | ||
if (z !== undefined || nullable && memory[b] !== undefined) return z!; | ||
if (z !== undefined || nullable && b in memory) return z!; | ||
z = f(...as); | ||
@@ -32,0 +47,0 @@ nullable ||= z === undefined; |
{ | ||
"name": "spica", | ||
"version": "0.0.734", | ||
"version": "0.0.735", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -19,7 +19,22 @@ import { isArray } from './alias'; | ||
if (typeof identify === 'object') return memoize(f, undefined, identify as Dict<b, z>); | ||
return isArray(memory) || memory?.constructor === Object | ||
? memoizeRecord(f, identify, memory as z[]) | ||
: memoizeDict(f, identify, memory as Dict<b, z> ?? new Map()); | ||
switch (true) { | ||
case isArray(memory): | ||
return memoizeArray(f, identify, memory as z[]); | ||
case memory?.constructor === Object: | ||
return memoizeObject(f, identify, memory as Record<number, z>); | ||
default: | ||
return memoizeDict(f, identify, memory as Dict<b, z> ?? new Map()); | ||
} | ||
} | ||
function memoizeRecord<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: Record<number, z>): typeof f { | ||
function memoizeArray<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: z[]): typeof f { | ||
return (...as) => { | ||
const b = identify(...as) as number; | ||
let z = memory[b]; | ||
if (z !== undefined) return z!; | ||
z = f(...as); | ||
memory[b] = z; | ||
return z; | ||
}; | ||
} | ||
function memoizeObject<as extends [unknown, ...unknown[]], z, b = as[0]>(f: (...as: as) => z, identify: (...as: as) => b, memory: Record<number, z>): typeof f { | ||
let nullable = false; | ||
@@ -29,3 +44,3 @@ return (...as) => { | ||
let z = memory[b]; | ||
if (z !== undefined || nullable && memory[b] !== undefined) return z!; | ||
if (z !== undefined || nullable && b in memory) return z!; | ||
z = f(...as); | ||
@@ -32,0 +47,0 @@ nullable ||= z === undefined; |
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
1158091
32350