/**
 * THIS FILE is for the content I intent to remove on Variant 3.0 that
 * I'm tired of seeing or considering in the code, so it gets shuffled
 * off to here.
 */ import { Defined , Handler , match } from './match' ; import { Func , Identity } from './util' ; import { Outputs , Property , VariantModule , VariantsOfUnion } from './variant' ; deprecated export type AugmentVariant < T extends VariantModule , U > = { [ P in keyof T ] : ( ( ... args : Parameters < T [ P ] > ) => Identity < ReturnType < T [ P ] > & U > ) & Outputs < T [ P ] [ 'key' ] , T [ P ] [ 'type' ] > ; } ; deprecated param variantDef param f export function augment < T extends VariantModule , F extends Func > ( variantDef , f ) { return Object . keys ( variantDef ) . reduce ( ( acc , key ) => { const augmentedFuncWrapper = ( ... args ) => ( Object . assign ( { } , f ( ) , variantDef [ key ] ( ... args ) ) ) ; return { ... acc , [ key ] : Object . assign ( augmentedFuncWrapper , { key : variantDef [ key ] . key , type : variantDef [ key ] . type } ) } ; } , { } as AugmentVariant < T , ReturnType < F > > ) ; } /**
 * Built to describe an object with the same keys as a variant but instead of constructors
 * for those objects has functions that handle objects of that type. In this case, the
 * keys are all partial and there is an extra option "default"
 */ export type DefaultedHandler < T , U = any > = Partial < Handler < T > & { default ? : ( union : T [ keyof T ] ) => U ; } > ; deprecated param obj param handler param typeKey export function partialMatch < T extends Property < K , string > , K extends string = 'type' > ( obj , handler , typeKey ? ) { return match ( obj , handler as any , typeKey ) as any ; } ; deprecated param obj param handler param { string ? } typeKey returns { The export function matchElse < T extends Property < K , string > , H extends Partial < Handler < VariantsOfUnion < T , K > > > , E extends ( rest : Exclude < T , Property < K , keyof H > > ) => any , K extends string = 'type' > ( obj , handler , _else , typeKey ? ) { const typeString = obj [ typeKey ?? 'type' as K ] ; return handler [ typeString ] ?. ( obj as any ) ?? _else ( obj as any ) ; }