since import { Applicative , Applicative1 , Applicative2 , Applicative3 } from 'fp-ts/lib/Applicative' ; import { Category2 } from 'fp-ts/lib/Category' ; import { Either } from 'fp-ts/lib/Either' ; import { flow , identity , Predicate , Refinement } from 'fp-ts/lib/function' ; import { HKT , Kind , Kind2 , Kind3 , URIS , URIS2 , URIS3 } from 'fp-ts/lib/HKT' ; import { Invariant2 } from 'fp-ts/lib/Invariant' ; import * as O from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { ReadonlyNonEmptyArray } from 'fp-ts/lib/ReadonlyNonEmptyArray' ; import { ReadonlyRecord } from 'fp-ts/lib/ReadonlyRecord' ; import { Semigroupoid2 } from 'fp-ts/lib/Semigroupoid' ; import { Traversable1 } from 'fp-ts/lib/Traversable' ; import * as _ from './internal' ; import { Iso } from './Iso' ; import { Lens } from './Lens' ; import { Optional } from './Optional' ; import { Traversal } from './Traversal' ; import Option = O . Option ; category since export interface Prism < S , A > { readonly getOption : ( s : S ) => Option < A > ; readonly reverseGet : ( a : A ) => S ; } category since export const prism = _ . prism ; category since export const id = < S > ( ) : Prism < S , S > => prism ( O . some , identity ) ; category since export const fromPredicate = _ . prismFromPredicate ; category since export const asOptional = _ . prismAsOptional ; category since export const asTraversal = _ . prismAsTraversal ; category since export const compose = _ . prismComposePrism ; category since export const composePrism = compose ; category since export const composeIso = flow ( _ . isoAsPrism , compose ) ; category since export const composeLens = _ . prismComposeLens ; category since export const composeOptional = < A , B > ( ab ) : ( < S > ( sa : Prism < S , A > ) => Optional < S , B > ) => flow ( asOptional , _ . optionalComposeOptional ( ab ) ) ; category since export const composeTraversal = < A , B > ( ab ) : ( < S > ( sa : Prism < S , A > ) => Traversal < S , B > ) => flow ( asTraversal , _ . traversalComposeTraversal ( ab ) ) ; category since export const set = _ . prismSet ; category since export const modifyOption = _ . prismModifyOption ; category since export const modify = _ . prismModify ; category since export function modifyF < F extends URIS3 > ( F ) ; export function modifyF < F extends URIS2 > ( F ) ; export function modifyF < F extends URIS > ( F ) ; export function modifyF < F > ( F ) ; export function modifyF < F > ( F ) { return ( f ) => ( sa ) => ( s ) => pipe ( sa . getOption ( s ) , O . fold ( ( ) => F . of ( s ) , ( a ) => F . map ( f ( a ) , sa . reverseGet ) ) ) ; } category since export const fromNullable = compose ( _ . prismFromNullable ( ) ) ; category since export function filter < A , B extends A > ( refinement ) ; export function filter < A > ( predicate ) ; export function filter < A > ( predicate ) { return compose ( _ . prismFromPredicate ( predicate ) ) ; } category since export const prop = < A , P extends keyof A > ( prop ) : ( < S > ( sa : Prism < S , A > ) => Optional < S , A [ P ] > ) => composeLens ( pipe ( _ . lensId < A > ( ) , _ . lensProp ( prop ) ) ) ; category since export const props = < A , P extends keyof A > ( ... props ) : ( < S > ( sa : Prism < S , A > ) => Optional < S , { [ K in P ] : A [ K ] ; } > ) => composeLens ( pipe ( _ . lensId < A > ( ) , _ . lensProps ( ... props ) ) ) ; category since export const component = < A extends ReadonlyArray < unknown > , P extends keyof A > ( prop ) : ( < S > ( sa : Prism < S , A > ) => Optional < S , A [ P ] > ) => composeLens ( pipe ( _ . lensId < A > ( ) , _ . lensComponent ( prop ) ) ) ; category since export const index = ( i ) : ( < S , A > ( sa : Prism < S , ReadonlyArray < A > > ) => Optional < S , A > ) => flow ( asOptional , _ . optionalIndex ( i ) ) ; category since export const indexNonEmpty = ( i ) : ( < S , A > ( sa : Prism < S , ReadonlyNonEmptyArray < A > > ) => Optional < S , A > ) => flow ( asOptional , _ . optionalIndexNonEmpty ( i ) ) ; category since export const key = ( key ) : ( < S , A > ( sa : Prism < S , ReadonlyRecord < string , A > > ) => Optional < S , A > ) => flow ( asOptional , _ . optionalKey ( key ) ) ; category since export const atKey = ( key ) => < S , A > ( sa ) : Optional < S , Option < A > > => _ . prismComposeLens ( _ . atReadonlyRecord < A > ( ) . at ( key ) ) ( sa ) ; category since export const some = compose ( _ . prismSome ( ) ) ; category since export const right = compose ( _ . prismRight ( ) ) ; category since export const left = compose ( _ . prismLeft ( ) ) ; category since export function traverse < T extends URIS > ( T ) { return flow ( asTraversal , _ . traversalTraverse ( T ) ) ; } category since export function findFirst < A , B extends A > ( refinement ) ; export function findFirst < A > ( predicate ) ; export function findFirst < A > ( predicate ) { return composeOptional ( _ . optionalFindFirst ( predicate ) ) ; } category since export function findFirstNonEmpty < A , B extends A > ( refinement ) ; export function findFirstNonEmpty < A > ( predicate ) ; export function findFirstNonEmpty < A > ( predicate ) { return composeOptional ( _ . optionalFindFirstNonEmpty ( predicate ) ) ; } category since export const imap = ( f , g ) => ( ea ) => imap_ ( ea , f , g ) ; const imap_ = ( ea , ab , ba ) => prism ( flow ( ea . getOption , O . map ( ab ) ) , flow ( ba , ea . reverseGet ) ) ; category since export const URI = 'monocle-ts/Prism' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind2 < E , A > { readonly [ URI ] : Prism < E , A > ; } } category since export const Invariant = { URI , imap : imap_ } ; category since export const Semigroupoid = { URI , compose : ( ab , ea ) => compose ( ab ) ( ea ) } ; category since export const Category = { URI , compose : Semigroupoid . compose , id } ;