Skip to content

Commit

Permalink
docs(memoize): update readme & pkg meta
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 3, 2024
1 parent 36d8865 commit 9049d81
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
32 changes: 22 additions & 10 deletions packages/memoize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

## About

Function memoization with configurable caching.
Function memoization with configurable caching and support for async functions.

This package provides different function memoization implementations for
functions with arbitrary arguments and custom result caching using ES6
Expand All @@ -48,10 +48,10 @@ based on different strategies. See doc strings for further details.
- [defOnce()](https://docs.thi.ng/umbrella/memoize/functions/defOnce.html)
- [delay()](https://docs.thi.ng/umbrella/memoize/functions/delay.html)
- [doOnce()](https://docs.thi.ng/umbrella/memoize/functions/doOnce.html)
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html)
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html)
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html)
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html)
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html) / [memoizeAsync()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync.html)
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html) / [memoizeAsync1()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync1.html)
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html) / [memoizeAsyncJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncJ.html)
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html) / [memoizeAsyncO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncO.html)

## Status

Expand Down Expand Up @@ -126,7 +126,10 @@ import { LRUCache } from "@thi.ng/cache";
```ts
import { memoize1 } from "@thi.ng/memoize";

foo = memoize1((x) => (console.log("exec"), x * 10));
foo = memoize1((x: number) => {
console.log("exec");
return x * 10;
});

foo(1);
// exec
Expand All @@ -138,7 +141,7 @@ import { EquivMap } from "@thi.ng/associative";

// with custom cache
foo = memoize1(
(x) => (console.log("exec"), x[0] * 10),
(x: number[]) => (console.log("exec"), x[0] * 10),
// custom ES6 Map impl which compares by value, not by reference
new EquivMap()
);
Expand All @@ -148,14 +151,15 @@ foo([1]);
// 10

// would be a cache miss w/ native ES6 Map
// due to lack of value equality semantics
foo([1]);
// 10

import { LRUCache } from "@thi.ng/cache";

// use LRU cache to limit cache size
foo = memoize1(
(x) => (console.log("exec"), x[0] * 10),
(x: number[]) => (console.log("exec"), x[0] * 10),
new LRUCache(null, { maxlen: 3 })
);
```
Expand All @@ -167,7 +171,10 @@ import { memoize } from "@thi.ng/memoize";
import { EquivMap } from "@thi.ng/associative";

const dotProduct = memoize(
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1]),
(x: number[], y: number[]) => {
console.log("exec");
return x[0] * y[0] + x[1] * y[1];
},
new EquivMap()
);

Expand All @@ -184,11 +191,16 @@ dotProduct([1,2], [3,4]);
import { memoizeJ } from "@thi.ng/memoize";

const dotProduct = memoizeJ(
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1])
(x: number[], y: number[]) => {
console.log("exec");
return x[0] * y[0] + x[1] * y[1];
}
);

dotProduct([1, 2], [3, 4]);
// exec
// 11

dotProduct([1, 2], [3, 4]);
// 11
```
Expand Down
3 changes: 2 additions & 1 deletion packages/memoize/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thi.ng/memoize",
"version": "4.0.0",
"description": "Function memoization with configurable caching",
"description": "Function memoization with configurable caching and support for async functions",
"type": "module",
"module": "./index.js",
"typings": "./index.d.ts",
Expand Down Expand Up @@ -45,6 +45,7 @@
"typescript": "^5.6.2"
},
"keywords": [
"async",
"cache",
"functional",
"memoization",
Expand Down
32 changes: 22 additions & 10 deletions packages/memoize/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ based on different strategies. See doc strings for further details.
- [defOnce()](https://docs.thi.ng/umbrella/memoize/functions/defOnce.html)
- [delay()](https://docs.thi.ng/umbrella/memoize/functions/delay.html)
- [doOnce()](https://docs.thi.ng/umbrella/memoize/functions/doOnce.html)
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html)
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html)
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html)
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html)
- [memoize()](https://docs.thi.ng/umbrella/memoize/functions/memoize.html) / [memoizeAsync()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync.html)
- [memoize1()](https://docs.thi.ng/umbrella/memoize/functions/memoize1.html) / [memoizeAsync1()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsync1.html)
- [memoizeJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeJ.html) / [memoizeAsyncJ()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncJ.html)
- [memoizeO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeO.html) / [memoizeAsyncO()](https://docs.thi.ng/umbrella/memoize/functions/memoizeAsyncO.html)

{{meta.status}}

Expand Down Expand Up @@ -64,7 +64,10 @@ import { LRUCache } from "@thi.ng/cache";
```ts
import { memoize1 } from "@thi.ng/memoize";

foo = memoize1((x) => (console.log("exec"), x * 10));
foo = memoize1((x: number) => {
console.log("exec");
return x * 10;
});

foo(1);
// exec
Expand All @@ -76,8 +79,8 @@ import { EquivMap } from "@thi.ng/associative";

// with custom cache
foo = memoize1(
(x) => (console.log("exec"), x[0] * 10),
// custom ES6 Map impl which compares by value, not by reference
(x: number[]) => (console.log("exec"), x[0] * 10),
// custom ES6 Map impl which compares by value, not by reference
new EquivMap()
);

Expand All @@ -86,14 +89,15 @@ foo([1]);
// 10

// would be a cache miss w/ native ES6 Map
// due to lack of value equality semantics
foo([1]);
// 10

import { LRUCache } from "@thi.ng/cache";

// use LRU cache to limit cache size
foo = memoize1(
(x) => (console.log("exec"), x[0] * 10),
(x: number[]) => (console.log("exec"), x[0] * 10),
new LRUCache(null, { maxlen: 3 })
);
```
Expand All @@ -105,7 +109,10 @@ import { memoize } from "@thi.ng/memoize";
import { EquivMap } from "@thi.ng/associative";

const dotProduct = memoize(
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1]),
(x: number[], y: number[]) => {
console.log("exec");
return x[0] * y[0] + x[1] * y[1];
},
new EquivMap()
);

Expand All @@ -122,11 +129,16 @@ dotProduct([1,2], [3,4]);
import { memoizeJ } from "@thi.ng/memoize";

const dotProduct = memoizeJ(
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1])
(x: number[], y: number[]) => {
console.log("exec");
return x[0] * y[0] + x[1] * y[1];
}
);

dotProduct([1, 2], [3, 4]);
// exec
// 11

dotProduct([1, 2], [3, 4]);
// 11
```
Expand Down

0 comments on commit 9049d81

Please sign in to comment.