* Walk `source`; for each key decide what to emit via the small callback. * * The callback returns either * • `undefined` → nothing is copied, or * • `[newKey, newVal]` * * so every public API just supplies a different callback.
( source: S, f: f )
| 830 | * so every public API just supplies a different callback. |
| 831 | */ |
| 832 | function buildStruct< |
| 833 | S extends object, |
| 834 | f extends (k: keyof S, v: S[keyof S]) => [PropertyKey, unknown] | undefined |
| 835 | >( |
| 836 | source: S, |
| 837 | f: f |
| 838 | ): any { |
| 839 | const out: Record<PropertyKey, unknown> = {} |
| 840 | for (const k of Reflect.ownKeys(source) as Array<keyof S>) { |
| 841 | if (!Object.prototype.propertyIsEnumerable.call(source, k)) continue |
| 842 | const res = f(k, source[k]) |
| 843 | if (res) { |
| 844 | const [nk, nv] = res |
| 845 | InternalRecord.assignProperty(out, nk, nv) |
| 846 | } |
| 847 | } |
| 848 | return out |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Creates a `Combiner` for a struct shape by providing a `Combiner` for each |