since import * as O from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { At } from './At' ; import * as _ from './internal' ; import { Iso } from './Iso' ; import { Optional } from './Optional' ; import * as RM from 'fp-ts/lib/ReadonlyMap' ; import { Eq } from 'fp-ts/lib/Eq' ; import Option = O . Option ; import { ReadonlyRecord } from 'fp-ts/lib/ReadonlyRecord' ; import { ReadonlyNonEmptyArray } from 'fp-ts/lib/ReadonlyNonEmptyArray' ; category since export interface Index < S , I , A > { readonly index : ( i : I ) => Optional < S , A > ; } category since export const index = _ . index ; category since export const fromAt = < T , J , B > ( at ) : Index < T , J , B > => index ( ( i ) => _ . lensComposePrism ( _ . prismSome < B > ( ) ) ( at . at ( i ) ) ) ; category since export const fromIso = < T , S > ( iso ) => < I , A > ( sia ) : Index < T , I , A > => index ( ( i ) => pipe ( iso , _ . isoAsOptional , _ . optionalComposeOptional ( sia . index ( i ) ) ) ) ; category since export const indexReadonlyArray = _ . indexReadonlyArray ; category since export const indexReadonlyNonEmptyArray = _ . indexReadonlyNonEmptyArray ; category since export const indexReadonlyRecord = _ . indexReadonlyRecord ; category since export const indexReadonlyMap = < K > ( E ) : ( < A = never > ( ) => Index < ReadonlyMap < K , A > , K , A > ) => { const lookupE = RM . lookup ( E ) ; const insertAtE = RM . insertAt ( E ) ; return ( ) => index ( ( key ) => _ . optional ( ( s ) => lookupE ( key , s ) , ( next ) => { const insert = insertAtE ( key , next ) ; return ( s ) => pipe ( lookupE ( key , s ) , O . fold ( ( ) => s , ( prev ) => ( next === prev ? s : insert ( s ) ) ) ) ; } ) ) ; } ; category since deprecated export const indexArray = _ . indexReadonlyArray ; category since deprecated export const indexRecord = _ . indexReadonlyRecord ;