/** * The {@link StdLib} module provides a set of standard libraries for common {@link Expression} patterns. * * @module StdLib * */ import { Expression } from './definition'; import { CalendarUnit, ConstFunction, EastFunction, RoundingMode, TimeUnit, Variable } from './functions'; import { ArrayType, BooleanType, DateTimeType, DictType, EastType, FloatType, IntegerType, Nullable, NullType, NumericType, PrimitiveType, PromoteType, SetType, StringType, StructType, VariantType } from './types'; /** * Update an existing field of a struct to a value of the same type. * * @category StdLib * * @see {@link Struct}, {@link Spread} */ export declare function SetField(struct: EastFunction, name: Name, value: EastFunction): EastFunction; /** * A helper function to assist in creating large structs. * It works identically to how object spreading works in JavaScript. * You can use it to either update existing fields in a struct, or to add new fields to a struct. * * @category StdLib * * @see {@link Struct}, {@link SetField} * * @example * ```ts * // build a struct with an additional field called new_field. * vars => Struct({ ...Spread(vars.large_struct), new_field: new_value }) * ``` */ export declare function Spread(x: EastFunction): { [K in keyof T["value"]]: EastFunction; }; /** * Comparison function between two expressions. * * @category StdLib */ export declare function Compare(a: Expression, b: Expression): EastFunction; /** * Return the lesser of `a` and `b` (note that `null` and `NaN` are greater than every other value). * * @category StdLib */ export declare function Min(a: Expression, b: Expression): EastFunction; export declare function Min(a: Expression, b: Expression): EastFunction; /** * Return the greater of `a` and `b` (note that `null` and `NaN` are greater than every other value). * * @category StdLib */ export declare function Max(a: Expression, b: Expression): EastFunction; export declare function Max(a: Expression, b: Expression): EastFunction; /** * Return true if `value` is `null` or `false` otherwise. * * @category StdLib */ export declare function IsNull(value: EastFunction): EastFunction; /** * Return true if `value` is `null` or `false` otherwise. * * @category StdLib */ export declare function IsNotNull(value: EastFunction): EastFunction; /** * Return an {@link EastType} for the option variant with cases "none" (indicating the lack of data) and "some" (indicating the presence of data). * * This is an alias for `VariantType({ none: NullType, some: type })`. * * @param type The `EastType` associated with the "some" case. * * @see {@link Some}, {@link Unwrap}, {@link MapOption}, {@link Option}. * * @category StdLib **/ export declare function OptionType(type: T): VariantType<{ none: NullType; some: T; }>; /** * Return an {@link EastType} for the Option variant with cases "none" (indicating the lack of data) and "some" (indicating the presence of data). * * This is an alias for `VariantType({ none: NullType, some: type })`. * * @param type The `EastType` associated with the "some" case. * * @see {@link Some}, {@link Unwrap}, {@link None}, {@link MapOption}. * * @category StdLib **/ export type OptionType = VariantType<{ none: NullType; some: T; }>; /** * An {@link EastFunction} containing the "none" case of the Option variant. This is an alias for `Const(none)`. * * @see {@link Some}, {@link Unwrap}, {@link MapOption}, {@link OptionType}. * * @category StdLib */ export declare const None: ConstFunction>; /** * Returns an {@link EastFunction} to construct the "some" case of the Option variant with associated data. This is an alias for `Variant("some", value)`. * * @param data An {@link EastFunction} containing the associated data. * * @see `None`, `Unrwap`, `MapOption`, `OptionType`, `some`. * @category StdLib */ export declare function Some(data: EastFunction): import("./functions").VariantFunction>; /** * Returns an {@link EastFunction} to unwrap an Option variant, replacing the "none" case with `defaultValue`. * * @param value An {@link EastFunction} for the Option variant. * @param defaultValue An {@link EastFunction} containing the associated data. * * @see {@link None}, {@link Some}, {@link MapOption}, {@link OptionType}. * * @category StdLib */ export declare function Unwrap(value: EastFunction>, defaultValue: EastFunction): EastFunction; export declare function Unwrap(value: EastFunction>, defaultValue: EastFunction): EastFunction; /** * Returns an {@link EastFunction} to map the data corresponding to the "some" case an Option variant through a function, while leaving the "none" case alone. * * @param value An {@link EastFunction} for the Option variant. * @param f A function of data associated with the "some" case returning an {@link EastFunction} for the new associated data. * * @see {@link None}, {@link Some}, {@link Unwrap}, {@link OptionType}. * * @category StdLib */ export declare function MapOption) => EastFunction>(value: EastFunction>, f: F): EastFunction["type"]>>; /** * Returns a {@link StringType} {@link EastFunction} for the tag of a {@link VariantType} {@link EastFunction}. * * @param value An {@link EastFunction} for the Option variant. * * @category StdLib */ export declare function GetTag, Fs extends { [K in keyof Variants]: ((v: Variable) => EastFunction); }>(value: EastFunction>): EastFunction; /** * Returns a {@link BooleanType} to determine if the tag of a {@link VariantType} {@link EastFunction} matches a supplied value. * * @param value An {@link EastFunction} for the Option variant. * @param tag the variant case (or tag) to test against * * @category StdLib */ export declare function HasTag(value: EastFunction, tag: Tag): EastFunction; /** * Returns a {@link EastType} to based on provided tag of a {@link VariantType} {@link EastFunction}. * * @param value An {@link EastFunction} for the Option variant. * @param tag the variant case (or tag) to test against * @param f the expression of the variant value * @param defaultValue the default value when the variant doesn't hag the tag * * @category StdLib */ export declare function MatchTag) => EastFunction>(value: EastFunction, tag: Tag, f: Fs, defaultValue: EastFunction): EastFunction; /** * Filter and map a collection (array or dictionary) of variants, keeping just one variant * case (or tag) and unwrapping the associated data. * * @param collection an {@link Expression} for a collection of variants * @param tag the variant case (or tag) to keep and unwrap * * @category StdLib */ export declare function FilterTag(collection: EastFunction>, tag: Tag): EastFunction>; export declare function FilterTag(collection: EastFunction>, tag: Tag): EastFunction>; /** * Pad the start of a string with a character up to a certain total length. * * @remarks it is assumed that `char` has length 1. * * @category StdLib */ export declare function PadStart(value: EastFunction, char: EastFunction | string, n: EastFunction | bigint): EastFunction; /** * Pad the end of a string with a character up to a certain total length. * * @remarks it is assumed that `char` has length 1. * * @category StdLib */ export declare function PadEnd(value: EastFunction, char: EastFunction | string, n: EastFunction | bigint): EastFunction; /** * Round datetime `value` down to a whole time `unit` ("year", "month", "week", "day", "hour", "minute", "second"). * * @category StdLib */ export declare function Floor(value: EastFunction, unit: TimeUnit | CalendarUnit): EastFunction; /** * Round number `value` down to nearest integer * * @category StdLib */ export declare function Floor(value: EastFunction, type: 'integer'): EastFunction : IntegerType>; /** * Round number `value` down to a whole number. * * @category StdLib */ export declare function Floor(value: EastFunction, type?: 'float'): EastFunction; /** * Round datetime `value` up to a whole time `unit` ("year", "month", "week", "day", "hour", "minute", "second"). * * @category StdLib */ export declare function Ceiling(value: EastFunction, unit: TimeUnit | CalendarUnit): EastFunction; /** * Round number `value` up to a whole number. * * @category StdLib */ export declare function Ceiling(value: EastFunction, type?: 'float'): EastFunction; /** * Round number `value` up to nearest integer. * * @category StdLib */ export declare function Ceiling(value: EastFunction, type?: 'integer'): EastFunction : IntegerType>; /** * Round number `value` up to nearest multiple of `divisor`. * * @category StdLib */ export declare function RoundMultiple(value: EastFunction, divisor: EastFunction, rounding_mode?: RoundingMode | undefined): EastFunction : T>; /** * Round number `value` towards zero to a whole number. * * @category StdLib */ export declare function Truncate(value: EastFunction, type?: 'float'): EastFunction; /** * Round number `value` towards zero to the nearest integer. * * @category StdLib */ export declare function Truncate(value: EastFunction, type?: 'integer'): EastFunction : IntegerType>; /** * Return a random number drawn from an exponential distribution. * * @category StdLib */ export declare function RandomExponential(): EastFunction; /** * Return a random number drawn from the Weibull distribution. * * @category StdLib */ export declare function RandomWeibull(shape: EastFunction): EastFunction; /** * Return a random subset of at most `n` keys from the input `collection`. * * @category StdLib */ export declare function RandomKeys(collection: EastFunction>, n: EastFunction): EastFunction>; export declare function RandomKeys(collection: EastFunction>, n: EastFunction): EastFunction>; export declare function RandomKeys(collection: EastFunction, n: EastFunction): EastFunction>; /** * Return a random subset of at most `n` values from the input `collection` (using sampling without replacement). * * @category StdLib */ export declare function RandomValues(collection: EastFunction>, n: EastFunction): EastFunction>; export declare function RandomValues(collection: EastFunction>, n: EastFunction): EastFunction>; /** * Return the number of whole weeks elapsed since the first Monday prior to or of the first day of the month. * * @category StdLib */ export declare function WeekOfMonth(date: EastFunction): EastFunction; /** * Convert a float {@link DictType} to an integer {@link DictType}. * * @category StdLib */ export declare function ConvertFloatDict(dict: EastFunction>): EastFunction>; /** * Convert an integer {@link DictType} to an float {@link DictType}. * * @category StdLib */ export declare function ConvertIntegerDict(dict: EastFunction>): EastFunction>; /** * Convert a number {@link Expression} to a magnitude string between ['negligible', 'moderate', 'large']. * * @category StdLib */ export declare function Importance(domain: Expression, range?: [negligible: number, moderate: number]): EastFunction; /** * Return a comma seperated and rounded currency string from an integer. * * @category StdLib */ export declare function PrintTruncatedCurrency(value: Expression): EastFunction; /** * Return a comma seperated and rounded currency string from a number. * * @category StdLib */ export declare function PrintTruncatedCurrency(value: Expression): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Monday. * * @category StdLib */ export declare function IsMonday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Tuesday. * * @category StdLib */ export declare function IsTuesday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Wednesday. * * @category StdLib */ export declare function IsWednesday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Thursday. * * @category StdLib */ export declare function IsThursday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Friday. * * @category StdLib */ export declare function IsFriday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Saturday. * * @category StdLib */ export declare function IsSaturday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a Sunday. * * @category StdLib */ export declare function IsSunday(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a weekend. * * @category StdLib */ export declare function IsWeekend(date: EastFunction): EastFunction; /** * Return the a boolean function to determine if a datetime {@link Expression} falls on a weekday. * * @category StdLib */ export declare function IsWeekday(date: EastFunction): EastFunction; /** * Return a {@link Print} function to convert a datetime {@link Expression} to a day of week name. * * @category StdLib */ export declare function DayName(date: EastFunction): import("./functions").GetFunction; /** * Return a {@link Print} function to convert a day of week {@link Expression} to a day of week name. * * @category StdLib */ export declare function DayInteger(day_name: EastFunction): import("./functions").GetFunction; /** * Return a {@link Print} function to convert a datetime {@link Expression} to an abbreviated day of week name. * * @category StdLib */ export declare function DayNameShort(date: EastFunction): import("./functions").GetFunction; /** * Return a {@link Print} function to convert a datetime {@link Expression} to an abbreviated month name. * * @category StdLib */ export declare function MonthNameShort(date: EastFunction): import("./functions").GetFunction; /** * Return `value` unless it equals `from`, in which case replace it with `to`. * * @category StdLib */ export declare function Replace(value: EastFunction, from: Expression, to: Expression): EastFunction; export declare function Replace(value: EastFunction, from: null, to: Expression): EastFunction; /** * Return `true` if `collection` has zero elements, or `false` otherwise. * * @category StdLib */ export declare function IsEmpty(collection: EastFunction): EastFunction; /** * Return the absolute value of a number or integer {@link Expression}. * * @category StdLib */ export declare function Abs(x: Expression): EastFunction; export declare function Abs(x: Expression): EastFunction; /** * Add all collection values into a single float or integer {@link Expression}. * * @category StdLib */ export declare function AddAll(collection: EastFunction>): EastFunction; export declare function AddAll(collection: EastFunction>): EastFunction; export declare function AddAll(collection: EastFunction>): EastFunction; export declare function AddAll(collection: EastFunction>): EastFunction; /** * Union all sets in `collection` into a single set {@link Expression}. * * @category StdLib */ export declare function UnionAll(collection: EastFunction | DictType>): EastFunction; /** * Return a {@link Print} function to convert a cycle {@link Expression} to an abbreviated week description. * * @category StdLib */ export declare function WeekDescription(cycle: EastFunction): EastFunction; /** * Print a number with a seperator between the thousands, e.g. 1234 as "1,234" * * @category StdLib */ export declare function PrintSeperated(x: Expression, thousands_seperator: string): EastFunction; /** * Return a {@link ArrayType} {@link EastFunction} to convert a dictionary into an array of key & value pairs * * @category StdLib */ export declare function ToEntries(dict: EastFunction>): EastFunction>>; /** * Return a number {@link EastFunction} to peform ... * * @category StdLib */ export declare function Sigmoid(x: EastFunction): EastFunction; /** * Convenience function to convert a datetime into a string for a key, rounding optional. * * @category StdLib */ export declare function DateKey(value: EastFunction, unit?: TimeUnit | CalendarUnit): EastFunction; /** * Convenience function to convert one or more expressions into a string for a key. * * @category StdLib */ export declare function PrimaryKey(...values: EastFunction[]): EastFunction; /** * Multiply `first` by `second` where both are dictionaries. * * @param first the first {@link Expression} to multiply * @param second the second {@link Expression} to multiply * * @category StdLib * * @example * ```typescript * // ... * // return the products revenue by multiplying the prices by the qtys * Amounts: MultiplyDict( * Variable('UnitPrices', DictType(StringType, FloatType)), * Variable('Quantities', DictType(StringType, FloatType)) * ), * // ... * ``` */ export declare function MultiplyDict(first: Expression>, second: Expression>): EastFunction>>; /** * Add `first` to `second` where both are dictionaries. * * @param first the first {@link Expression} to add * @param second the second {@link Expression} to add * * @remarks Missing keys between first and second are assumed to have a value of 0. * * @category StdLib * * @example * ```typescript * // ... * // return the prices by dividing the total amounts by the qtys * NewBalance: AddDict( * Variable('InitialBalance', DictType(StringType, FloatType)), * Variable('Amount', DictType(StringType, FloatType)) * ), * // ... * ``` */ export declare function AddDict(d1: EastFunction>, d2: EastFunction>): import("./functions").MapValuesFunction>;