/** * @tsplus type Match/Ops */ export interface MatchOps { $: MatchAspects } export const Match: MatchOps = { $: {} } /** * @tsplus type Match/Aspects */ export interface MatchAspects {} /** * @tsplus static Match/Aspects pattern */ export const pattern: ( n: N ) => { < X extends { [k in N]: string }, K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( _: K ): (m: X) => ReturnType < X extends { [k in N]: string }, K extends Partial< { [k in X[N]]: ( _: Extract, __: Extract ) => any } >, H >( _: & K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): (m: X) => { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => ((_: any, d: any) => (m: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any /** * @tsplus static Match/Aspects tag */ export const matchTag = pattern("_tag") /** * @tsplus static Match/Ops pattern */ export const pattern_: ( n: N ) => { < X extends { [k in N]: string }, K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( m: X, _: K ): ReturnType < X extends { [k in N]: string }, K extends Partial< { [k in X[N]]: ( _: Extract, __: Extract ) => any } >, H >( m: X, _: & K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => ((m: any, _: any, d: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any /** * @tsplus static Match/Ops tag */ export const matchTag_ = pattern_("_tag") /** * @tsplus static Match/Aspects patternFor */ export const patternFor: ( n: N ) => () => { < K extends { [k in X[N]]: ( _: Extract, __: Extract ) => any } >( _: K ): (m: X) => ReturnType < K extends Partial< { [k in X[N]]: ( _: Extract, __: Extract ) => any } >, H >( _: & K & { [k in X[N]]?: ( _: Extract, __: Extract ) => any }, __: (_: Exclude, __: Exclude) => H ): (m: X) => { [k in keyof K]: ReturnType> }[keyof K] | H } = (n) => () => ((_: any, d: any) => (m: any) => { return (_[m[n]] ? _[m[n]](m, m) : d(m, m)) as any }) as any /** * @tsplus static Match/Ops tagFor */ export const matchTagFor = patternFor("_tag") /** * @tsplus static Match/Ops isAdtElement */ export function isAdtElement_( tag: K, adt: A ): adt is Extract { return adt["_tag"] === tag } /** * @tsplus static Match/Aspects isAdtElement */ export const isAdtElement = Pipeable(isAdtElement_) /** * @tsplus static Match/Ops isGenericAdtElement */ export function isGenericAdtElement( _t: T ): ( tag: K ) => (adt: A) => adt is Extract { return (tag: K) => (adt: A): adt is Extract => adt[_t] === tag } /** * @tsplus static Match/Ops onAdtElement */ export function onAdtElement( tag: K, f: (_: Extract) => B ): (adt: A) => Maybe { return (adt: A) => { if (adt["_tag"] === tag) { return Maybe.some(f(adt as any)) } return Maybe.none } } /** * @tsplus static Match/Ops onGenericAdtElement */ export function onGenericAdtElement(_t: T) { return ( tag: K, f: (_: Extract) => B ) => (adt: A): Maybe => { if (adt[_t] === tag) { return Maybe.some(f(adt as any)) } return Maybe.none } }