@thi.ng/memoize 3.1.61 → 3.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +23 -8
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -105,27 +105,37 @@ import { LRUCache } from "@thi.ng/cache";
|
|
|
105
105
|
### Optimized version for single arg functions
|
|
106
106
|
|
|
107
107
|
```ts
|
|
108
|
-
|
|
108
|
+
import { memoize1 } from "@thi.ng/memoize";
|
|
109
|
+
|
|
110
|
+
foo = memoize1((x) => (console.log("exec"), x * 10));
|
|
111
|
+
|
|
109
112
|
foo(1);
|
|
110
113
|
// exec
|
|
111
114
|
// 10
|
|
112
115
|
foo(1);
|
|
113
116
|
// 10
|
|
114
117
|
|
|
118
|
+
import { EquivMap } from "@thi.ng/associative";
|
|
119
|
+
|
|
115
120
|
// with custom cache
|
|
116
|
-
foo =
|
|
121
|
+
foo = memoize1(
|
|
117
122
|
(x) => (console.log("exec"), x[0] * 10),
|
|
123
|
+
// custom ES6 Map impl which compares by value, not by reference
|
|
118
124
|
new EquivMap()
|
|
119
125
|
);
|
|
120
126
|
|
|
121
127
|
foo([1]);
|
|
122
128
|
// exec
|
|
123
129
|
// 10
|
|
124
|
-
|
|
130
|
+
|
|
131
|
+
// would be a cache miss w/ native ES6 Map
|
|
132
|
+
foo([1]);
|
|
125
133
|
// 10
|
|
126
134
|
|
|
135
|
+
import { LRUCache } from "@thi.ng/cache";
|
|
136
|
+
|
|
127
137
|
// use LRU cache to limit cache size
|
|
128
|
-
foo =
|
|
138
|
+
foo = memoize1(
|
|
129
139
|
(x) => (console.log("exec"), x[0] * 10),
|
|
130
140
|
new LRUCache(null, { maxlen: 3 })
|
|
131
141
|
);
|
|
@@ -134,7 +144,10 @@ foo = m.memoize1(
|
|
|
134
144
|
### Arbitrary args
|
|
135
145
|
|
|
136
146
|
```ts
|
|
137
|
-
|
|
147
|
+
import { memoize } from "@thi.ng/memoize";
|
|
148
|
+
import { EquivMap } from "@thi.ng/associative";
|
|
149
|
+
|
|
150
|
+
const dotProduct = memoize(
|
|
138
151
|
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1]),
|
|
139
152
|
new EquivMap()
|
|
140
153
|
);
|
|
@@ -149,13 +162,15 @@ dotProduct([1,2], [3,4]);
|
|
|
149
162
|
### Via JSON.stringify()
|
|
150
163
|
|
|
151
164
|
```ts
|
|
152
|
-
|
|
165
|
+
import { memoizeJ } from "@thi.ng/memoize";
|
|
166
|
+
|
|
167
|
+
const dotProduct = memoizeJ(
|
|
153
168
|
(x, y) => (console.log("exec"), x[0] * y[0] + x[1] * y[1])
|
|
154
169
|
);
|
|
155
|
-
dotProduct([1,2], [3,4]);
|
|
170
|
+
dotProduct([1, 2], [3, 4]);
|
|
156
171
|
// exec
|
|
157
172
|
// 11
|
|
158
|
-
dotProduct([1,2], [3,4]);
|
|
173
|
+
dotProduct([1, 2], [3, 4]);
|
|
159
174
|
// 11
|
|
160
175
|
```
|
|
161
176
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/memoize",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.63",
|
|
4
4
|
"description": "Function memoization with configurable caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
33
33
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
34
34
|
"pub": "yarn npm publish --access public",
|
|
35
|
-
"test": "bun test"
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.9.
|
|
39
|
+
"@thi.ng/api": "^8.9.28"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@microsoft/api-extractor": "^7.40.1",
|
|
@@ -89,5 +90,5 @@
|
|
|
89
90
|
],
|
|
90
91
|
"year": 2018
|
|
91
92
|
},
|
|
92
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "a421058a65ba76608d94129ac29451bfedaf201c\n"
|
|
93
94
|
}
|