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

Method optionalKey

packages/effect/src/Optic.ts:994–1017  ·  view source on GitHub ↗
(key: PropertyKey)

Source from the content-addressed store, hash-verified

992 return make(compose(this.node, [new PathNode([key])]))
993 }
994 optionalKey(key: PropertyKey): any {
995 return make(
996 compose(
997 this.node,
998 primitiveNode(
999 "Lens",
1000 (s) => s[key],
1001 (a, s) => {
1002 const copy = cloneShallow(s)
1003 if (a === undefined) {
1004 if (Array.isArray(copy) && typeof key === "number") {
1005 copy.splice(key, 1)
1006 } else {
1007 delete copy[key]
1008 }
1009 } else {
1010 InternalRecord.assignProperty(copy, key, a)
1011 }
1012 return copy
1013 }
1014 )
1015 )
1016 )
1017 }
1018 check(...checks: readonly [SchemaAST.Check<any>, ...Array<SchemaAST.Check<any>>]): any {
1019 return make(compose(this.node, [new CheckNode(checks)]))
1020 }

Callers

nothing calls this directly

Calls 4

primitiveNodeFunction · 0.85
cloneShallowFunction · 0.85
makeFunction · 0.70
composeFunction · 0.70

Tested by

no test coverage detected