MCPcopy Create free account
hub / github.com/effect-app/libs / buildStruct

Function buildStruct

repos/effect/packages/effect/src/Struct.ts:826–843  ·  view source on GitHub ↗

* 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
)

Source from the content-addressed store, hash-verified

824 * Walk `source`; for each key decide what to emit via the small callback.
825 *
826 * The callback returns either
827 * • `undefined` → nothing is copied, or
828 * • `[newKey, newVal]`
829 *
830 * so every public API just supplies a different callback.
831 */
832function 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 }

Callers 1

Struct.tsFile · 0.85

Calls 1

fFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…