import * as O from "optics-ts"
import * as L from "./lens"
export type LensLike =
| L.Lens
| O.Lens
| O.Equivalence
| O.Iso
const supportedOpticsTags = ["Lens", "Equivalence", "Iso"]
export function mkLens(lens: LensLike): L.Lens {
const tag: string | undefined = (lens as any)._tag
if (tag) {
// Optics.ts lens
if (!supportedOpticsTags.includes(tag)) {
throw Error(
`Only ${supportedOpticsTags.join(
"/"
)} optics supported from optics-ts. Given optic is a ${tag}.`
)
}
const opticsLens = lens as O.Lens
return {
get: O.get(opticsLens),
set: (current: A, data: B) => O.set(opticsLens)(data)(current),
}
}
return lens as L.Lens
}