import { DeleteFunction, EastFunction, FilterFunction, FilterMapFunction, GetFunction, InFunction, InsertFunction, MapValuesFunction, ReduceFunction, SizeFunction, UpdateFunction, Variable } from '../functions'; import { ArrayType, BlobType, BooleanType, DictType, EastType, EastTypeOf, IntegerType, NullType, PrimitiveValue, SetType, StringType, Value, ValueTypeOf, VariantType } from '../types'; import { Expression } from './core'; /** * Return `true` if `key` is in `set`, or `false` otherwise. * * @param set the {@link Expression} for the set * @param key the {@link Expression} for the value to search for * * @category Expression * * @example * ```typescript * // ... * // Determine if the product is in the set of currently available products * ProductIsAvailable: In( * Variable("AvailableProductIds", SetType), * Variable("ProductId", StringType), * ), * // ... * ``` */ export declare function In(collection: EastFunction, key: bigint): InFunction; export declare function In(collection: EastFunction, key: EastFunction): InFunction; export declare function In>(collection: EastFunction, key: U): InFunction; export declare function In(collection: EastFunction, key: EastFunction): InFunction; export declare function In>(setcollection: EastFunction, key: U): InFunction; export declare function In(collection: EastFunction, key: EastFunction): InFunction; /** * Return a dictionary where `key` has been inserted with `value` into `collection`, * overwriting an existing value if it exists. * * Note: the input `collection` is unmodified (you need to use the return value) * * @param collection the {@link Expression} for the dictionary * @param key the {@link Expression} for the key to insert * @param value the {@link Expression} for the value to insert * * @category Expression * * @example * ```typescript * Insert(dict, key, value) * ``` */ export declare function Insert>>(collection: EastFunction, key: Expression, value: EastFunction): InsertFunction; export declare function Insert(collection: EastFunction, key: Expression, value: ValueTypeOf): InsertFunction; /** * Return a set where `key` has been inserted into `collection`. * * Note: the input `collection` is unmodified (you need to use the return value) * * @param collection the {@link Expression} for the set * @param key the {@link Expression} for the key to insert * * @category Expression * * @example * ```typescript * Insert(set, key) * ``` */ export declare function Insert(collection: EastFunction, key: Expression): InsertFunction; /** * Return an array where `value` has been inserted to the start or end of `collection`. * * Note: the input `collection` is unmodified (you need to use the return value) * * @param collection the {@link Expression} for the array * @param key must be `"first"` or `"last"` * @param value the {@link Expression} for the value to insert * * @category Expression * * @example * ```typescript * Insert(array, "last", value) * ``` */ export declare function Insert>>(collection: EastFunction, key: "first" | "last", value: EastFunction): InsertFunction; export declare function Insert(collection: EastFunction, key: "first" | "last", value: ValueTypeOf["value"]>): InsertFunction; /** * Return an array where `key` has been updated with `value` into `collection`, * overwriting the existing value. * * Note: the input `collection` is unmodified (you need to use the return value). * * @param collection the {@link Expression} for the array * @param key the {@link Expression} for the key (i.e. index) to update * @param value the {@link Expression} for the value to update * * @category Expression * * @example * ```typescript * Update(array, index, value) * ``` */ export declare function Update>>(collection: EastFunction, key: bigint | EastFunction, value: EastFunction): UpdateFunction; export declare function Update(collection: EastFunction, key: bigint | EastFunction, value: ValueTypeOf["value"]>): UpdateFunction; /** * Return an dictionary where `key` has been updated with `value` into `collection`, * overwriting the existing value. * * Note: the input `collection` is unmodified (you need to use the return value). * * @param collection the {@link Expression} for the dictionary * @param key the {@link Expression} for the key to update * @param value the {@link Expression} for the value to update * * @category Expression * * @example * ```typescript * Update(dict, key, value) * ``` */ export declare function Update>>(collection: EastFunction, key: string | EastFunction, value: EastFunction): UpdateFunction; export declare function Update(collection: EastFunction, key: string | EastFunction, value: ValueTypeOf["value"]["value"]>): UpdateFunction; /** * Return a dictionary with a given `key` deleted from `collection`. * * Note: the input `collection` is unmodified (you need to use the return value) * * @param collection the {@link Expression} for the dictionary * @param key the {@link Expression} for the key to delete * * @category Expression * * @example * ```typescript * Delete(dict, key) * ``` */ export declare function Delete(collection: EastFunction, key: Expression): DeleteFunction; /** * Return a set with a given `key` deleted from `collection`. * * @param collection the {@link Expression} for the set * @param key the {@link Expression} for the key to delete * * Note: currently this mutates `collection`, which can have unintended consequences if it is used elsewhere. * * @category Expression * * @example * ```typescript * Delete(set, key) * ``` */ export declare function Delete(collection: EastFunction, key: Expression): DeleteFunction; /** * Return an array with the last element deleted. * * @param collection the {@link Expression} for the array * * Note: currently this mutates `collection`, which can have unintended consequences if it is used elsewhere. * * @category Expression * * @example * ```typescript * Delete(array, "last") * ``` */ export declare function Delete(collection: EastFunction, key: "first" | "last"): DeleteFunction; /** * Get a value from `collection` corresponding to the given `key`. If `key` is not found, returns `default`. * * @param collection the {@link Expression} for the dictionary * @param key the {@link Expression} for the (string) key * @param default the {@link Expression} for the value to return if the key is not found (optional, if not provided results in runtime error) * * @category Expression * @example * ```typescript * // ... * // Get the name of a product from a dictionary from id -> name * ProductName: Get( * Variable("ProductNames", DictType(StringType)), * Variable("ProductId", StringType), * null * ), * // ... * ``` */ export declare function Get(collection: EastFunction, key: EastFunction, defaultValue: D & ((D["type"] & T["value"]["value"]) extends never ? never : unknown)): GetFunction; export declare function Get(collection: EastFunction, key: EastFunction, defaultValue: D & ((EastTypeOf & T["value"]["value"]) extends never ? never : unknown)): GetFunction & T["value"]["value"]>; export declare function Get(collection: EastFunction, key: EastFunction): GetFunction; /** * Get a value from `collection` corresponding to the given `key`. If `key` is not found, * returns `default`. (Note: the first key of an array is zero). * * @param collection the {@link Expression} for the array * @param key the {@link Expression} for the (integer) key * @param default the {@link Expression} for the value to return if the key is not found (optional, if not provided results in runtime error) * * @category Expression * * @example * ```typescript * // ... * // Get the first item in a list of items * FirstItem: Get( * Variable("Items", ArrayType(StringType)), * 0n * ), * // ... * ``` */ export declare function Get(collection: EastFunction, key: EastFunction, defaultValue: D & ((D["type"] & T["value"]) extends never ? never : unknown)): GetFunction; export declare function Get(collection: EastFunction, key: EastFunction, defaultValue: D & ((EastTypeOf & T["value"]) extends never ? never : unknown)): GetFunction & T["value"]>; export declare function Get(collection: EastFunction, key: EastFunction): GetFunction; /** * Get the number of elements in a collection. * * @param collection the {@link Expression} for the array, dictionary or set * * @category Expression * * @example * ```typescript * // ... * // Get the number of employees on a shift * NumberOfShiftEmployees: Size( * Variable("ShiftEmployeeIds", SetType), * ), * // ... * ``` */ export declare function Size(collection: EastFunction): SizeFunction; /** * Return a set containing only values where the `predicate` was `true`. * * @param collection the {@link Expression} for the input set * @param predicate a function from the input key to an {@link Expression} to calculate whether to keep the element * * @category Expression * * @example * ```typescript * // ... * // Get only the non-null elements of a set * SubscriptionProducts: Filter( * Variable("ProductIds", SetType(StringType)), * productId => Get( * Variable("ProductIsSubscription", BooleanType), * productId * ) * ), * // ... * ``` */ export declare function Filter) => EastFunction>(collection: EastFunction, predicate: Pred): FilterFunction; /** * Return a dictionary containing only values where the `predicate` was `true`. * * @param collection the {@link Expression} for the input dictionary * @param predicate a function from the input value and key to an {@link Expression} to calculate whether to keep the element * * @category Expression * * @example * ```typescript * // ... * // Get only the non-null elements of a dictionary * FilteredDict: Filter( * Variable("Dict", DictType(StringType, Nullable(StringType))), * value => NotEqual(value, null) * ), * // ... * ``` */ export declare function Filter, key: Variable) => EastFunction>(collection: EastFunction, predicate: Pred): FilterFunction; /** * Return an array containing only values where the `predicate` was `true`. * * @param collection the {@link Expression} for the input array * @param predicate a function from the input value and key to an {@link Expression} to calculate whether to keep the element * * @category Expression * * @example * ```typescript * // ... * // Get only the non-null elements of an array * FilteredArray: Filter( * Variable("Array", ArrayType(Nullable(StringType))), * value => NotEqual(value, null) * ) * // ... * ``` */ export declare function Filter, key: Variable) => EastFunction>(collection: EastFunction, predicate: Pred): FilterFunction; /** * Return a dictionary mapping the keys of a set through a function. The output keys match * the input set. * * @param collection the {@link Expression} for the input set * @param value a function from the input key to an {@link Expression} to calculate the output value * * @deprecated use ToDict instead * * @category Expression * * @example * ```typescript * // ... * // Create full names for each of a set of employees * SomeEmployeeNames: MapDict( * Variable("SomeEmployeeIds", SetType), * employeeId => StringJoin`${Get(Variable("EmployeeFirstNames", DictType(StringType)), employeeId)} ${Get(Variable("EmployeeLastNames", DictType(StringType)), employeeId)}`, * ), * // ... * ``` */ export declare function MapDict) => EastFunction>(collection: EastFunction, value: U): MapValuesFunction["type"]>>; /** * Return a dictionary mapping the values of a dictionary through a function. The output * keys match the keys of the input dictionary. * * @param collection the {@link Expression} for the input dictionary * @param value a function from the input value and key to an {@link Expression} to calculate the output value * * @deprecated use ToDict instead * * @category Expression * * @example * ```typescript * // ... * // Calculate the total price from collections of product unit price and quantity * ProductTotalPrices: MapDict( * Variable("ProductQuantities", DictType(StringType, IntegerType)), * (quantity, productId) => Multiply( * quantity, * Get( * Variable("ProductUnitPrices", DictType(StringType, IntegerType)), * productId * ) * ) * ) * // ... * ``` */ export declare function MapDict, key: Variable) => EastFunction>(collection: EastFunction, value: U): MapValuesFunction["type"]>>; /** * Return an array mapping and filtering the entries of an array via a function returning an Option variant. * The data in the "some" case is kept, while the "none" case is discarded (filtered out). * The ordering of entries is preserved. * * @param collection the {@link Expression} for the input array * @param value a function from the input key to an {@link Expression} to calculate the output value as an option variant * * @category Expression */ export declare function FilterMap, key: Variable) => EastFunction>>(collection: EastFunction, value: U): FilterMapFunction["type"]["value"]["some"]>>; /** * Return a set mapping and filtering the entries of a set via a function returning an Option variant. * The data in the "some" case is kept, while the "none" case is discarded (filtered out). * * @param collection the {@link Expression} for the input set * @param value a function from the input key to an {@link Expression} to calculate the output value as an option variant * * @category Expression */ export declare function FilterMap) => EastFunction>>(collection: EastFunction, value: U): FilterMapFunction["type"]["value"]["some"]>>; /** * Return a dictionary mapping and filtering the entries of a dictionary via a function returning an Option variant. * The data in the "some" case is kept, while the "none" case is discarded (filtered out). * The output keys match the keys of the input dictionary. * * @param collection the {@link Expression} for the input dictionary * @param value a function from the input value and key to an {@link Expression} to calculate the output value as an option variant * @category Expression * @see `mapFilter` * */ export declare function FilterMap, key: Variable) => EastFunction>>(collection: EastFunction, value: U): FilterMapFunction["type"]["value"]["some"]>>; /** * Loop over the values in an array in order, performing a reduction. * * Each reduction starts with an `initial` value. For every element of the collection, the * `reducer` calculates a new value based on both the data and the result of the `previous` * iteration. The `previous` variable acts to transfer state from one iteration to the next. * * Reductions can be quite powerful - while many are simple (e.g. summing an array), it * is possible to construct rich data structures incrementally through a reduction. * * @param collection - the {@link Expression} for the input collection to be reduced over * @param reducer - a function of the `previous` value and input `value` and `key` variables returning an {@link Expression} giving the next value of the reduction * @param initial - an {@link Expression} for the initial value of the reduction * @param previous - a {@link Variable} holding the current state of the reduction * * @category Expression * * @example * ```typescript * // To add up all the values in an array of integers * Reduce( * array, * (previous, value) => Add(previous, value), * Const(0n) * ) * ``` */ export declare function Reduce, value: Variable, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & I["type"]) extends never ? never : unknown), initial: I): ReduceFunction["type"] & I["type"]>; export declare function Reduce>, value: Variable, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & EastTypeOf) extends never ? never : unknown), initial: I): ReduceFunction["type"] & EastTypeOf>; /** * Loop over the values in an array in order, performing a reduction. * * Each reduction starts with an `initial` value. For every element of the collection, the * `reducer` calculates a new value based on both the data and the result of the `previous` * iteration. The `previous` variable acts to transfer state from one iteration to the next. * * Reductions can be quite powerful - while many are simple (e.g. summing an array), it * is possible to construct rich data structures incrementally through a reduction. * * @param collection - the {@link Expression} for the input collection to be reduced over * @param reducer - a function of the `previous` value and input `key` variables returning an {@link Expression} giving the next value of the reduction * @param initial - an {@link Expression} for the initial value of the reduction * @returns The final output of `reducer`, or else `initial` for empty collections * * @category Expression * * @example * ```typescript * // Given a `set` of `key`s, calculate the sum of the corresponding values in * // an integer dictionary `dict` * Reduce( * set, * (previous, key) => Add(previous, Get(dict, key), * Const(0n) * ) * ``` */ export declare function Reduce, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & I["type"]) extends never ? never : unknown), initial: I): ReduceFunction["type"] & I["type"]>; export declare function Reduce>, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & EastTypeOf) extends never ? never : unknown), initial: I): ReduceFunction["type"] & EastTypeOf>; /** * Loop over the values in an array in order, performing a reduction. * * Each reduction starts with an `initial` value. For every element of the collection, the * `reducer` calculates a new value based on both the data and the result of the `previous` * iteration. The `previous` variable acts to transfer state from one iteration to the next. * * Reductions can be quite powerful - while many are simple (e.g. summing an array), it * is possible to construct rich data structures incrementally through a reduction. * * @param collection - the {@link Expression} for the input collection to be reduced over * @param reducer - a function of the `previous` value and input `value` and `key` variables returning an {@link Expression} giving the next value of the reduction * @param initial - an {@link Expression} for the initial value of the reduction * @returns The final output of `reducer`, or else `initial` for empty collections * * @category Expression * * @example * ```typescript * // To add up all the values in a dictionary of integers * Reduce( * * dict, * (previous, value) => Add(previous, value), * Const(0n) * ) * ``` */ export declare function Reduce, value: Variable, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & I["type"]) extends never ? never : unknown), initial: I): ReduceFunction["type"] & I["type"]>; export declare function Reduce>, value: Variable, key: Variable) => EastFunction>(collection: EastFunction, reducer: R & ((ReturnType["type"] & EastTypeOf) extends never ? never : unknown), initial: I): ReduceFunction["type"] & EastTypeOf>;