(node: Node)
| 1178 | } |
| 1179 | |
| 1180 | function make(node: Node): any { |
| 1181 | let op: Operation = node[0] ?? identityOperation |
| 1182 | if (node.length > 1) { |
| 1183 | const kind = node.reduce<Kind>((kind, step) => composeKind(kind, step.kind), "Iso") |
| 1184 | op = { |
| 1185 | kind, |
| 1186 | get: compileGet(node, kind), |
| 1187 | set: compileSet(node, kind) |
| 1188 | } |
| 1189 | } |
| 1190 | switch (op.kind) { |
| 1191 | case "Iso": |
| 1192 | return new IsoImpl(node, op.get, op.set) |
| 1193 | case "Lens": |
| 1194 | return new LensImpl(node, op.get, op.set) |
| 1195 | case "Prism": |
| 1196 | return new PrismImpl(node, op.get, op.set) |
| 1197 | case "Optional": |
| 1198 | return new OptionalImpl(node, op.get, op.set) |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | function cloneShallow<T>(pojo: T): T { |
| 1203 | if (Array.isArray(pojo)) return pojo.slice() as T |
no test coverage detected