(node: Node)
| 1163 | } |
| 1164 | |
| 1165 | function make(node: Node): any { |
| 1166 | let op: Operation = node[0] ?? identityOperation |
| 1167 | if (node.length > 1) { |
| 1168 | const kind = node.reduce<Kind>((kind, step) => composeKind(kind, step.kind), "Iso") |
| 1169 | op = { |
| 1170 | kind, |
| 1171 | get: compileGet(node, kind), |
| 1172 | set: compileSet(node, kind) |
| 1173 | } |
| 1174 | } |
| 1175 | switch (op.kind) { |
| 1176 | case "Iso": |
| 1177 | return new IsoImpl(node, op.get, op.set) |
| 1178 | case "Lens": |
| 1179 | return new LensImpl(node, op.get, op.set) |
| 1180 | case "Prism": |
| 1181 | return new PrismImpl(node, op.get, op.set) |
| 1182 | case "Optional": |
| 1183 | return new OptionalImpl(node, op.get, op.set) |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | function cloneShallow<T>(pojo: T): T { |
| 1188 | if (Array.isArray(pojo)) return pojo.slice() as T |
no test coverage detected