// ets_tracing: off import { pipe } from "@effect-ts/core/Function" import type { Option } from "@effect-ts/core/Option" import type { HashMap } from "@effect-ts/system/Collections/Immutable/HashMap" import type { At } from "../At/index.js" import * as _ from "../Internal/index.js" import type { Iso } from "../Iso/index.js" import type { Optional } from "../Optional/index.js" // ------------------------------------------------------------------------------------- // model // ------------------------------------------------------------------------------------- export interface Index { readonly index: (i: I) => Optional } // ------------------------------------------------------------------------------------- // constructors // ------------------------------------------------------------------------------------- export const fromAt = (at: At>): Index => ({ index: (i) => _.lensComposePrism(_.prismSome())(at.at(i)) }) /** * Lift an instance of `Index` using an `Iso` */ export const fromIso = (iso: Iso) => (sia: Index): Index => ({ index: (i) => pipe(iso, _.isoAsOptional, _.optionalComposeOptional(sia.index(i))) }) export const indexArray: () => Index, number, A> = _.indexArray export const indexRecord: () => Index< Readonly>, string, A > = _.indexRecord export const indexHashMap: () => Index< Readonly>, K, A > = _.indexHashMap