Skip to content

Commit 81c6349

Browse files
committed
refactor: re-export objectMap from Endo
1 parent 3368e9e commit 81c6349

File tree

1 file changed

+2
-46
lines changed

1 file changed

+2
-46
lines changed

packages/internal/src/utils.js

+2-46
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isPromise, makePromiseKit } from '@endo/promise-kit';
77
import { makeQueue } from '@endo/stream';
88
import { asyncGenerate, makeSet } from 'jessie.js';
99

10-
const { entries, fromEntries, keys, values } = Object;
10+
const { fromEntries, keys, values } = Object;
1111
const { ownKeys } = Reflect;
1212

1313
const { details: X, quote: q, Fail } = assert;
@@ -42,51 +42,7 @@ export const fromUniqueEntries = allEntries => {
4242
};
4343
harden(fromUniqueEntries);
4444

45-
/**
46-
* By analogy with how `Array.prototype.map` will map the elements of
47-
* an array to transformed elements of an array of the same shape,
48-
* `objectMap` will do likewise for the string-named own enumerable
49-
* properties of an object.
50-
*
51-
* Typical usage applies `objectMap` to a CopyRecord, i.e.,
52-
* an object for which `passStyleOf(original) === 'copyRecord'`. For these,
53-
* none of the following edge cases arise. The result will be a CopyRecord
54-
* with exactly the same property names, whose values are the mapped form of
55-
* the original's values.
56-
*
57-
* When the original is not a CopyRecord, some edge cases to be aware of
58-
* * No matter how mutable the original object, the returned object is
59-
* hardened.
60-
* * Only the string-named enumerable own properties of the original
61-
* are mapped. All other properties are ignored.
62-
* * If any of the original properties were accessors, `Object.entries`
63-
* will cause its `getter` to be called and will use the resulting
64-
* value.
65-
* * No matter whether the original property was an accessor, writable,
66-
* or configurable, all the properties of the returned object will be
67-
* non-writable, non-configurable, data properties.
68-
* * No matter what the original object may have inherited from, and
69-
* no matter whether it was a special kind of object such as an array,
70-
* the returned object will always be a plain object inheriting directly
71-
* from `Object.prototype` and whose state is only these new mapped
72-
* own properties.
73-
*
74-
* With these differences, even if the original object was not a CopyRecord,
75-
* if all the mapped values are Passable, then the returned object will be
76-
* a CopyRecord.
77-
*
78-
* @template {Record<string, any>} O
79-
* @param {O} original
80-
* @template R map result
81-
* @param {(value: O[keyof O], key: keyof O) => R} mapFn
82-
* @returns {{ [P in keyof O]: R}}
83-
*/
84-
export const objectMap = (original, mapFn) => {
85-
const ents = entries(original);
86-
const mapEnts = ents.map(([k, v]) => [k, mapFn(v, k)]);
87-
return harden(fromEntries(mapEnts));
88-
};
89-
harden(objectMap);
45+
export { objectMap } from '@endo/patterns';
9046

9147
/**
9248
* @param {Array<string | symbol>} leftNames

0 commit comments

Comments
 (0)