import { Either , EitherPatterns , Maybe , MaybePatterns } from '..' ; interface CaseOfable { caseOf < T > ( pattern ) : T ; } export type CaseOf = { < M extends CaseOfable , P extends getPatternsOfADT < M > , T2 = getReturn_T_ofPattern < P > > ( p ) : ( m : M ) => T2 ; } ; export type Match = CaseOf ; export const caseOf = ( p ) => ( m ) => m . caseOf ( p ) ; export const match = ( p ) => ( m ) => m . caseOf ( p ) ; type getPatternsOfADT < M > = M extends Either < infer L , infer R > ? EitherPatterns < L , R , any > : M extends Maybe < infer T > ? MaybePatterns < T , any > : never ; type getReturn_T_ofPattern < P > = P extends EitherPatterns < any , any , infer R > | EitherPatterns < any , never , infer R > | EitherPatterns < never , any , infer R > ? R : P extends MaybePatterns < any , infer R > | MaybePatterns < never , infer R > ? R : never ;