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

Function cloneShallow

packages/effect/src/Optic.ts:1202–1212  ·  view source on GitHub ↗
(pojo: T)

Source from the content-addressed store, hash-verified

1200}
1201
1202function cloneShallow<T>(pojo: T): T {
1203 if (Array.isArray(pojo)) return pojo.slice() as T
1204 if (typeof pojo === "object" && pojo !== null) {
1205 const proto = Object.getPrototypeOf(pojo)
1206 if (proto !== Object.prototype && proto !== null) {
1207 throw new Error("Cannot clone object with non-Object constructor or null prototype")
1208 }
1209 return { ...pojo } as T
1210 }
1211 return pojo
1212}
1213
1214function compileGet(nodes: Node, kind: Kind): (s: any) => any {
1215 return (s) => {

Callers 3

constructorMethod · 0.85
optionalKeyMethod · 0.85
atMethod · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected