import { AstType, EastFunction, KeysFunction, NewDictFunction, OnlyKeyFunction, ToDictFunction, Variable } from '../functions'; import { ArrayType, DictType, EastType, EastTypeOf, IntegerType, Nullable, SetType, StringType, SubType, Value, ValueTypeOf } from '../types'; import { Expression } from './core'; /** * Construct an new dictionary with the given `keys` and `values`. * * @param key_type the {@link EastType} the keys of the dictionary will be * @param value_type the {@link EastType} the values of the dictionary will be * @param keys an array of {@link Expression}s to insert as keys into the new dictionary (optional) * @param values an array of {@link Expression}s to insert as values into the new dictionary (must be the same length as `keys`) (optional) * * @category Expression * * @example * ```typescript * // create a new empty dictionary with string keys and integer values * NewDict(StringType, IntegerType) * // create a new dictionary containing entries ["a", 1n] and ["b", 2n] * NewDict(StringType, IntegerType, [Const("a"), Const("b")], [Const(1n), Const(2n)]) * ``` */ export declare function NewDict(key_type: K, value_type: T, keys?: Expression[], values?: (ValueTypeOf> | { type: SubType>; ast_type: AstType; })[]): NewDictFunction>; /** * Return a dictionary where each output `key` and `value` is calculated from elements of the input `collection`. * If the `key` is `null` the element is ignored. In case of duplicate keys, the last value is kept, unless initial_value * is provided in which case the previous value can be used to calculate the new value. * * @param collection the {@link Expression} for the input set * @param value a function from the input key (and previous value) to an {@link Expression} to calculate the output value * @param key a function from the input key to an {@link Expression} to calculate the output key * @param initial_value an expression for an initial value given to each key and passed into `value` * * @category Expression * * @example * ```typescript * // create a new dictionary mapping the keys of a set to their uppercase values * ToDict( * set, * x => UpperCase(x), * x => x, * ) * ``` */ export declare function ToDict) => EastFunction>(collection: EastFunction, value: VOut): ToDictFunction["type"]>>; export declare function ToDict) => EastFunction, KOut extends (key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, initial_value: Variable

) => EastFunction, KOut extends (key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: EastFunction

): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, initial_value: Variable>) => EastFunction, KOut extends (key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: P): ToDictFunction["type"], ReturnType["type"]>>; /** * Return a dictionary where each output `key` and `value` is calculated from elements of the input `collection`. * If the `key` is `null` the element is ignored. In case of duplicate keys, the last value is kept, unless initial_value * is provided in which case the previous value can be used to calculate the new value. * * @param collection the {@link Expression} for the input array * @param value a function from the input value and key (and previous value) to an {@link Expression} to calculate the output value * @param key a function from the input value and key to an {@link Expression} to calculate the output key * @param initial_value an expression for an initial value given to each key and passed into `value` * * @category Expression * * @example * ```typescript * // create a new dictionary mapping the elements of an array to their uppercase values * ToDict( * array, * x => UpperCase(x), * x => x, * ) * ``` */ export declare function ToDict, key: Variable) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, key: Variable, initial_value: Variable

) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: EastFunction

): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, key: Variable, initial_value: Variable>) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: P): ToDictFunction["type"], ReturnType["type"]>>; /** * Return a dictionary where each output `key` and `value` is calculated from elements of the input `collection`. * If the `key` is `null` the element is ignored. In case of duplicate keys, the last value is kept, unless initial_value * is provided in which case the previous value can be used to calculate the new value. * * @param collection the {@link Expression} for the input dictionary * @param value a function from the input value and key (and previous value) to an {@link Expression} to calculate the output value * @param key a function from the input value and key to an {@link Expression} to calculate the output key * @param initial_value an expression for an initial value given to each key and passed into `value` * * @category Expression * @example * ```typescript * // create a new dictionary incrementing the integer values of the input dictionary * ToDict( * dict, * (value, key) => Add(value, 1n), * (value, key) => key, * ) * ``` */ export declare function ToDict, key: Variable) => EastFunction>(collection: EastFunction, value: VOut): ToDictFunction["type"]>>; export declare function ToDict, key: Variable) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, key: Variable, initial_value: Variable

) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: EastFunction

): ToDictFunction["type"], ReturnType["type"]>>; export declare function ToDict, key: Variable, initial_value: Variable>) => EastFunction, KOut extends (value: Variable, key: Variable) => EastFunction>(collection: EastFunction, value: VOut, key: KOut, initial_value: P): ToDictFunction["type"], ReturnType["type"]>>; /** * Return the set of keys of `dict`. * * @param dict the {@link Expression} for the dictionary * * @category Expression * * @example * ```typescript * // ... * // Given a dictionary from product quantities to price, get the set of product ids * ProductIds: Keys(Variable("ProductQuantities", DictType(IntegerType))), * // ... * ``` */ export declare function Keys(dict: EastFunction): KeysFunction>; /** * Return the only key of `dict`, or else `null` if it has zero or more than two elements. * * @param dict the {@link Expression} for the dictionary * * @category Expression */ export declare function OnlyKey(dict: EastFunction): OnlyKeyFunction>;