import { MergeTypes } from '../../utils/types'; import { EastFunction, VariantFunction, Variable } from '../functions'; import { EastType, EastTypeOf, NullType, PrimitiveValue, Value, ValueTypeOf, VariantType } from '../types'; /** * Return an {@link EastFunction} that constructs a variant with a given case (or tag) and associated value. * * @param case A string tag identifying which case the constructed variant is * @param value An optional {@link EastFunction} to create the data assocated with this variant (default `null`) * * @category Expression * @see {@link Match} * * @example * ```typescript * // ... * // Calculate the average price from an array of historical prices, `priceHistory`. * // An Option variant is returned - the none case for when the array is empty, and otherwise the some case wraps the mean. * AveragePrice: IfElse( * Greater(Size(priceHistory), 0n), * Variant("some", Divide( * AddAll(priceHistory), * Size(priceHistory) * )), * Variant("none"), * ) * // ... * ``` */ export declare function Variant(tag: Tag): VariantFunction>; export declare function Variant(tag: Tag, data: EastFunction): VariantFunction>; export declare function Variant(tag: Tag, data: T): VariantFunction; }>>; export declare function Variant(tag: Tag, data: D & (D["type"] & V["value"][Tag] extends never ? never : unknown), type: V): VariantFunction; export declare function Variant(tag: Tag, data: D & (ValueTypeOf & V["value"][Tag] extends never ? never : unknown), type: V): VariantFunction; /** * Match an expression depending on the cases (or tags) of an input variant. * This is the primary method to access a variant's case (or tag) and any associated data. * * @param input the {@link EastFunction} for the input variant * @param functions a function returning an {@link EastFunction} for each possible case or tag of the input variant * @param defaultValue an optional {@link EastFunction} for any possible case or tag not listed in `functions` * * @category Expression * @see {@link Variant} * * @example * ```typescript * // ... * // Get the name of the product from the product data, or else return the string "####" * ProductName: Match( * Variable("ProductName", VariantType({ some: StringType, none: NullType })), * { * some: name => name * none: _ => "####" * }, * ) * // ... * ``` */ export declare function Match, Fs extends { [K in keyof Variants]: ((v: Variable) => EastFunction); }>(input: EastFunction>, functions: Fs, defaultValue?: EastFunction): MergeTypes<{ [Tag in keyof Variants]: ReturnType["type"]; }> extends never ? unknown : { ast_type: "Match"; type: MergeTypes<{ [Tag in keyof Variants]: ReturnType["type"]; }>; input: EastFunction; functions: Record; value: string; }; export declare function Match, Fs extends { [K in keyof Variants]?: ((v: Variable) => EastFunction); }, D extends EastType>(input: EastFunction>, functions: Fs, defaultValue: EastFunction): (D & MergeTypes<{ [Tag in keyof Fs]: ReturnType>["type"]; }>) extends never ? unknown : { ast_type: "Match"; type: (D & MergeTypes<{ [Tag in keyof Fs]: ReturnType>["type"]; }>); input: EastFunction; functions: Record; value: string; };