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

Method optionalKey

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

Source from the content-addressed store, hash-verified

1004 return make(compose(this.node, [new PathNode([key])]))
1005 }
1006 optionalKey(key: PropertyKey): any {
1007 return make(
1008 compose(
1009 this.node,
1010 primitiveNode(
1011 "Lens",
1012 (s) => s[key],
1013 (a, s) => {
1014 const copy = cloneShallow(s)
1015 if (a === undefined) {
1016 if (
1017 Array.isArray(copy) &&
1018 (typeof key === "number" || (typeof key === "string" && Arr.isCanonicalArrayIndex(key)))
1019 ) {
1020 copy.splice(Number(key), 1)
1021 } else {
1022 delete copy[key]
1023 }
1024 } else {
1025 InternalRecord.assignProperty(copy, key, a)
1026 }
1027 return copy
1028 }
1029 )
1030 )
1031 )
1032 }
1033 check(...checks: readonly [SchemaAST.Check<any>, ...Array<SchemaAST.Check<any>>]): any {
1034 return make(compose(this.node, [new CheckNode(checks)]))
1035 }

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected