MCPcopy Create free account
hub / github.com/Effect-TS/effect / buildStruct

Function buildStruct

packages/effect/src/Struct.ts:832–849  ·  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

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 }
847 }
848 return out
849}
850
851/**
852 * Creates a `Combiner` for a struct shape by providing a `Combiner` for each

Callers 1

Struct.tsFile · 0.85

Calls 1

fFunction · 0.50

Tested by

no test coverage detected