Skip to main content

Expressions

The

Expressions module facilitates creation of statically typed functional data Expression's, as well as providing a set of standard libraries for common Expression patterns.

Example

// Given a `set` of `key`s, calculate the sum of the corresponding values in
// an integer dictionary `dict`
Count: Reduce(
set,
(previous, key) => Add(previous, Get(dict, key),
Const(0n)
)

Example

 // ...
// if name is null, replace with 'Unknown' string
Wage: Let(
Max(0, Subtract(Variable("Hours", FloatType), 8),
overtime => Add(
Multiply(
Variable("NormalRate", FloatType),
Subtract(Variable("Hours", FloatType), overtime)
),
Multiply(
Variable("OvertimeRate", FloatType),
overtime
)
)
),
// ...

Expression

Expression

Ƭ Expression<T>: ValueTypeOf<T> | EastFunction<T>

An

Expression may either be a Value or EastFunction

Type parameters

NameType
Textends EastType = EastType

Add

Add<T, U>(first, second): EastFunction<T>

Add first to second. These can either be integer of float expressions. Combining float with integer will result in a float.

Type parameters

NameType
Textends IntegerType | FloatType
Uextends number | bigint

Parameters

NameTypeDescription
firstUthe first Expression to add
secondEastFunction<T>the second Expression to add

Returns

EastFunction<T>

Example

 // ...
// return the bank balance after a sale is deposited
NewBalance: Add(
Variable('Balance', FloatType),
Variable('SaleTotal', FloatType)
),
// return the number of stock after a quantity is purchased
NewStockLevel: Add(
Variable('StockLevel', IntegerType),
Variable('PurchaseQuantity', IntegerType)
),
// ...

AddDuration

AddDuration<T, U>(datetime, duration, unit): EastFunction<T extends

NullType ? Nullable<DateTimeType> : U extends NullType ? Nullable<DateTimeType> : DateTimeType>

Add the duration (in the given time unit) to datetime.

Type parameters

NameType
Textends DateTimeType
Uextends FloatType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for the initial datetime
durationExpression<U>the Expression for duration
unitTimeUnitthe TimeUnit of duration ('millisecond', 'second', 'minute', 'hour', 'day' or 'week')

Returns

EastFunction<T extends

NullType ? Nullable<DateTimeType> : U extends NullType ? Nullable<DateTimeType> : DateTimeType>

Example

 // ...
// return the date payment is due for an invoice according to the invoice terms
DueDate: AddDuration(
Variable('PurchaseDate', DateTimeType),
Variable('InvoiceTermDays', FloatType),
'day'
),
// ...

And

And(): EastFunction<

BooleanType>

Return true if all values are true, or false otherwise.

Returns

EastFunction<

BooleanType>

Example

 // ...
// set an employee availability to true if they are a "Site Worker" AND they started more than 6 months ago
Available: And(
Equal(
Variable('EmployeeCategory', 'strings'),
Const("Site Worker")
),
Greater(
Duration(
Variable('StartDate', DateTimeType),
Variable('ContractDate', DateTimeType),
'month'
),
6
)
),
// ...

AsciiToBase64

AsciiToBase64(value): AsciiToBase64Function<

StringType>

Convert an ASCII string to Base64 encoding.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the input ASCII string

Returns

AsciiToBase64Function<

StringType>


Base64ToAscii

Base64ToAscii(value): Base64ToAsciiFunction<

StringType>

Convert a Base64 string to an ASCII string.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the input Base64 string

Returns

Base64ToAsciiFunction<

StringType>


Base64ToHex

Base64ToHex(value): Base64ToHexFunction<

StringType>

Convert a Base64 string to hexadecimal encoding.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the input Base64 string

Returns

Base64ToHexFunction<

StringType>


Const

Const<T>(value, type): ConstFunction<T>

Declare a constant value, specifying the type explicitly. Providing the type may be necessary when it is impossible to determine the type from the value alone - e.g. for nullable types, or for empty arrays, sets, or dictionaries.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueValueTypeOf<T>the Value to declare
typeT-

Returns

ConstFunction<T>

Example

 // ...
// create a constant string 'New Employee'
category: Const('New Employee', NullableString),
// ...

Const<T>(value): ConstFunction<EastTypeOf<T>>

Declare a constant value, inferring the type automatically from the value.

Note: In some cases the East type cannot be easily inferred, and the corresponding type should be provided as a second argument.

Type parameters

NameType
Textends Value

Parameters

NameTypeDescription
valueTthe Value to declare

Returns

ConstFunction<EastTypeOf<T>>

Example

 // ...
// create a constant string 'New Employee'
category: Const('New Employee'),
// ...

Convert

Convert(from, type): EastFunction<

Nullable<FloatType>>

Convert from to the specified type.

Note: the output may approximate large integers by the nearest 64-bit floating-point value.

Parameters

NameTypeDescription
fromEastFunction<Nullable<IntegerType>>the Expression to convert
typeNullable<FloatType>the EastType to convert to

Returns

EastFunction<

Nullable<FloatType>>

Example

 // ...
// convert a percentage to a ratio
Ratio: Divide(Convert(Variable('Percentage', IntegerType), FloatType), 100),
// ...

Convert(from, type): EastFunction<

Nullable<IntegerType>>

Convert from to the specified type.

Note: the output may approximate floating-point numbers by rounding towards zero to the nearest 64-bit signed-integer value. NaN is converted to 0n.

Parameters

NameTypeDescription
fromEastFunction<Nullable<FloatType>>the Expression to convert
typeNullable<IntegerType>the EastType to convert to

Returns

EastFunction<

Nullable<IntegerType>>

Example

 // ...
// convert a ratio to a percentage
Percentage: Convert(Multiply(Variable('Ratio', FloatType), 100), IntegerType),
// ...

Cos

Cos<T>(value): EastFunction<T>

Return the cosine of a number. The input is specified in radians.

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for the angle

Returns

EastFunction<T>

Example

 // ...
// calculate the cosine of an angle
cos_x: Cos(x),
// ...

DayOfMonth

DayOfMonth<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the day number of the month (1 - 31).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


DayOfWeek

DayOfWeek<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole days elapsed since the start of the week (Monday = 0, ..., Sunday = 6).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


Default

Default<T>(type): EastFunction<T>

Create an EastFunction returning the default value of a given type.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
typeTthe EastType

Returns

EastFunction<T>

See

DefaultValue


Delete

Delete<T>(collection, key): DeleteFunction<T>

Return a dictionary with a given key deleted from collection.

Note: the input collection is unmodified (you need to use the return value)

Type parameters

NameType
Textends DictType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the dictionary
keyExpression<T["value"]["key"]>the Expression for the key to delete

Returns

DeleteFunction<T>

Example

Delete(dict, key)

Delete<T>(collection, key): DeleteFunction<T>

Return a set with a given key deleted from collection.

Type parameters

NameType
Textends SetType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the set
keyExpression<T["value"]>the Expression for the key to delete Note: currently this mutates collection, which can have unintended consequences if it is used elsewhere.

Returns

DeleteFunction<T>

Example

Delete(set, key)

Delete<T>(collection, key): DeleteFunction<T>

Return an array with the last element deleted.

Type parameters

NameType
Textends ArrayType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the array Note: currently this mutates collection, which can have unintended consequences if it is used elsewhere.
key"first" | "last"-

Returns

DeleteFunction<T>

Example

Delete(array, "last")

Divide

Divide<T, U>(first, second): EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>

Divide first by second.

Type parameters

NameType
Textends IntegerType | FloatType
Uextends number | bigint

Parameters

NameTypeDescription
firstUthe initial Expression to divide
secondEastFunction<T>the Expression to divide by

Returns

EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>

Example

 // ...
// return the average revenue collected each trading day
RevenuePerDay: Divide(
Variable('TotalRevenue', FloatType),
Variable('DaysOpen', FloatType)
),
// ...

Duration

Duration<T, U>(start, stop, unit): EastFunction<T extends

NullType ? Nullable<FloatType> : U extends NullType ? Nullable<FloatType> : FloatType>

Find the duration between datetimes start and stop, in the given time unit. Note: returns a negative number if stop is prior to start (and that the ordering of arguments is reversed compared to

Subtract).

Type parameters

NameType
Textends DateTimeType
Uextends DateTimeType

Parameters

NameTypeDescription
startEastFunction<T>the Expression for the initial datetime
stopEastFunction<U>the Expression for the final datetime
unitTimeUnitthe TimeUnit to calculate the answer in ('millisecond', 'second', 'minute', 'hour', 'day' or 'week')

Returns

EastFunction<T extends

NullType ? Nullable<FloatType> : U extends NullType ? Nullable<FloatType> : FloatType>

Example

 // ...
// return the length of a shift in hours
ShiftHours: Duration(
Variable('ShiftStart', DateTimeType),
Variable('ShiftStop', DateTimeType),
'hour'
),
// ...

Equal

Equal<T>(first, second): EastFunction<

BooleanType>

Compare two values and return true if equal, or false otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if an employee is a "Site Worker"
IsSiteWorker: Equal(
Variable('EmployeeCategory', StringType),
Const("Site Worker")
),
// ...

Exp

Exp<T>(value): EastFunction<T>

Return the (natural) exponential of a number (i.e. power with base e).

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for the exponent

Returns

EastFunction<T>

Example

 // ...
// transform a variable from a logarithmic space to normal space
XExp: Exp(Variable('X', FloatType)),
// ...

Filter

Filter<T, Pred>(collection, predicate): FilterFunction<T>

Return a set containing only values where the predicate was true.

Type parameters

NameType
Textends SetType
Predextends (key: Variable<T["value"]>) => EastFunction<BooleanType>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input set
predicatePreda function from the input key to an Expression to calculate whether to keep the element

Returns

FilterFunction<T>

Example

// ...
// Get only the non-null elements of a set
SubscriptionProducts: Filter(
Variable("ProductIds", SetType(StringType)),
productId => Get(
Variable("ProductIsSubscription", BooleanType),
productId
)
),
// ...

Filter<T, Pred>(collection, predicate): FilterFunction<T>

Return a dictionary containing only values where the predicate was true.

Type parameters

NameType
Textends DictType
Predextends (value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction<BooleanType>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input dictionary
predicatePreda function from the input value and key to an Expression to calculate whether to keep the element

Returns

FilterFunction<T>

Example

// ...
// Get only the non-null elements of a dictionary
FilteredDict: Filter(
Variable("Dict", DictType(StringType, Nullable(StringType))),
value => NotEqual(value, null)
),
// ...

Filter<T, Pred>(collection, predicate): FilterFunction<T>

Return an array containing only values where the predicate was true.

Type parameters

NameType
Textends ArrayType
Predextends (value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction<BooleanType>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input array
predicatePreda function from the input value and key to an Expression to calculate whether to keep the element

Returns

FilterFunction<T>

Example

// ...
// Get only the non-null elements of an array
FilteredArray: Filter(
Variable("Array", ArrayType(Nullable(StringType))),
value => NotEqual(value, null)
)
// ...

FilterMap

FilterMap<T, U>(collection, value): FilterMapFunction<

ArrayType<ReturnType<U>["type"]["value"]["some"]>>

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.

Type parameters

NameType
Textends ArrayType
Uextends (value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction<VariantType<{ none: NullType ; some: EastType }>>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input array
valueUa function from the input key to an Expression to calculate the output value as an option variant

Returns

FilterMapFunction<

ArrayType<ReturnType<U>["type"]["value"]["some"]>>

FilterMap<T, U>(collection, value): FilterMapFunction<

SetType<ReturnType<U>["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).

Type parameters

NameType
Textends SetType
Uextends (key: Variable<T["value"]>) => EastFunction<VariantType<{ none: NullType ; some: StringType }>>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input set
valueUa function from the input key to an Expression to calculate the output value as an option variant

Returns

FilterMapFunction<

SetType<ReturnType<U>["type"]["value"]["some"]>>

FilterMap<T, U>(collection, value): FilterMapFunction<

DictType<T["value"]["key"], ReturnType<U>["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.

Type parameters

NameType
Textends DictType
Uextends (value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction<VariantType<{ none: NullType ; some: EastType }>>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input dictionary
valueUa function from the input value and key to an Expression to calculate the output value as an option variant

Returns

FilterMapFunction<

DictType<T["value"]["key"], ReturnType<U>["type"]["value"]["some"]>>

See

mapFilter


FromCsv

FromCsv<T>(type, value, parsers?, options?): FromCsvFunction<T>

Return a array of structs from data encoded in a CSV blob.

Type parameters

NameType
Textends ArrayType<StructType>

Parameters

NameTypeDescription
typeTthe EastType of the output to decode (column names should match the CSV file)
valueEastFunction<BlobType>the Expression with the blob value to decode from CSV
parsers{ [K in string | number | symbol]?: Function }an object containing functions returning Expressions to parse each field (e.g. to parse the format a date-time)
optionsPartial<FromCsvOptions>provide options for formatting the CSV files (such as delimeters, null sentinels, and headers)

Returns

FromCsvFunction<T>

Example

FromCsv(
ArrayType(StructType({ id: StringType, date: DateTimeType, qty: Nullable(IntegerType) })),
blob,
{ date: x => Parse(x, "YYYY-MM-DD") },
{ nullString: "NA" }
)

FromJson

FromJson<U, T>(type, value): EastFunction<T>

Return an East value of type type decoded from a JSON string (similar to JSON.parse).

Note: this expects the JSON to conform to some known schema compatible with type.

Type parameters

NameType
Uextends StringType
Textends EastType

Parameters

NameTypeDescription
typeTthe EastType to decode to
valueEastFunction<U>the Expression with the JSON string to decode

Returns

EastFunction<T>

Example

// decode a JSON array of strings
FromJson(ArrayType(StringType), string)

Get

Get<T, D>(collection, key, defaultValue): GetFunction<D["type"] & T["value"]["value"]>

Get a value from collection corresponding to the given key. If key is not found, returns default.

Type parameters

NameType
Textends DictType
Dextends EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the dictionary
keyEastFunction<T["value"]["key"]>the Expression for the (string) key
defaultValueD & D["type"] & T["value"]["value"] extends never ? never : unknown-

Returns

GetFunction<D["type"] & T["value"]["value"]>

Example

 // ...
// Get the name of a product from a dictionary from id -> name
ProductName: Get(
Variable("ProductNames", DictType(StringType)),
Variable("ProductId", StringType),
null
),
// ...

Get<T, D>(collection, key, defaultValue): GetFunction<D["type"] & T["value"]>

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).

Type parameters

NameType
Textends ArrayType
Dextends EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the array
keyEastFunction<IntegerType>the Expression for the (integer) key
defaultValueD & D["type"] & T["value"] extends never ? never : unknown-

Returns

GetFunction<D["type"] & T["value"]>

Example

 // ...
// Get the first item in a list of items
FirstItem: Get(
Variable("Items", ArrayType(StringType)),
0n
),
// ...

GetField

GetField<T, K>(struct, field): GetFieldFunction<T["value"][K]>

Fetch the value of one of a struct's fields.

Type parameters

NameType
Textends StructType
Kextends string | number | symbol

Parameters

NameTypeDescription
structEastFunction<T>the Expression for the input struct
fieldKthe name of field to fetch

Returns

GetFieldFunction<T["value"][K]>

See

Struct

Example

// ...
// Get the name of the product from the product data
ProductName: GetField(
Variable(product_data, StructType({
Id: StringType,
Name: StringType,
UnitPrice: FloatType,
StockLevel: IntegerType,
StockTakeDate: DateTimeType,
}),
"Name"
),
// ...

Greater

Greater<T>(first, second): EastFunction<

BooleanType>

Compare two values and return true if the first is greater than the second, or false otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if more than 8 hours were worked
IsOvertime: Greater(
Variable('HoursWorked', FloatType),
8
),
// ...

GreaterEqual

GreaterEqual<T>(first, second): EastFunction<

BooleanType>

Compare two values and return true if the first is greater than or equal to the second, or false otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if balance is greater or equal to zero.
IsSolvent: GreaterEqual(
Variable('Balance', FloatType),
0
),
// ...

HMAC

HMAC(value, key, hash, encoding): HMACFunction<

StringType>

Return the HMAC for a string with a given key and specified hashing algorithm and encoding.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the string to sign
keyEastFunction<StringType>the Expression for the HMAC key
hashHashTypethe HashType to employ ('md5', 'sha1', 'sha256', 'sha224', 'sha512', 'sha384', 'sha3' or 'ripemd160')
encoding"base64" | "hex"the encoding the result should be use ('base64' or 'hex')

Returns

HMACFunction<

StringType>

Example

HMAC(string, key, 'sha256', 'base64')

Hash

Hash(value, hash, encoding): HashFunction<

StringType>

Return the hash of a string with specified algorithm and encoding.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the string to hash
hashHashTypethe HashType to employ ('md5', 'sha1', 'sha256', 'sha224', 'sha512', 'sha384', 'sha3' or 'ripemd160')
encoding"base64" | "hex"the encoding the result should be use ('base64' or 'hex')

Returns

HashFunction<

StringType>

Example

Hash(string, 'sha256', 'base64')

HexToBase64

HexToBase64(value): HexToBase64Function<

StringType>

Convert a hexadecimal string to Base64 encoding.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the input hexadecimal string

Returns

HexToBase64Function<

StringType>


Hour

Hour<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole hours elapsed since the start of the day (0 - 23).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


IfElse

IfElse<F1, F2>(predicate, x1, x2): EastFunction<F1 extends any ? F1["type"] & F2["type"] : never>

Return x1 of predicate is true, or x2 otherwise

Type parameters

NameType
F1extends EastFunction
F2extends EastFunction

Parameters

NameTypeDescription
predicateEastFunction<BooleanType>the Expression to test
x1F1the return value if predicate is true
x2F2 & F1["type"] & F2["type"] extends never ? never : unknownthe return value if predicate is false

Returns

EastFunction<F1 extends any ? F1["type"] & F2["type"] : never>

Example

 // ...
// if name is null, replace with 'Unknown' string
new_name: IfElse(
Equal(Variable('name', Nullable(StringType)), Null(StringType)),
Const('Unknown'),
Variable('name', StringType)
),
// ...

IfNull

IfNull<T, N, V>(input, out_null, out_value): IfNullFunction<EastTypeOf<N>> & IfNullFunction<ReturnType<V>["type"]>

Return x1 of predicate is null, or x2 otherwise

Type parameters

NameType
Textends Nullable
Nextends PrimitiveValue
Vextends (x: Variable<NonNullable<T>>) => EastFunction

Parameters

NameTypeDescription
inputEastFunction<T>the nullable Expression to test
out_nullNthe return value if input is null
out_valueV & EastTypeOf<N> & ReturnType<V>["type"] extends never ? never : unknowna function of value to evaluate if input is not null (defaults to value => value)

Returns

IfNullFunction<EastTypeOf<N>> & IfNullFunction<ReturnType<V>["type"]>

Example

 // if name is null, replace with 'Unknown' string
IfNull(
name,
Const('Unknown')
)
// if name is null, replace with 'UNKNOWN' string, otherwise make it uppercase
IfNull(
name,
Const('UNKNOWN'),
non_null_name => UpperCase(non_null_name)
)

In

In<T>(collection, key): InFunction<

BooleanType>

Return true if key is in set, or false otherwise.

Type parameters

NameType
Textends ArrayType

Parameters

NameTypeDescription
collectionEastFunction<T>-
keybigintthe Expression for the value to search for

Returns

InFunction<

BooleanType>

Example

 // ...
// Determine if the product is in the set of currently available products
ProductIsAvailable: In(
Variable("AvailableProductIds", SetType<StringType>),
Variable("ProductId", StringType),
),
// ...

Insert

Insert<V, T>(collection, key, value): InsertFunction<T>

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)

Type parameters

NameType
Vextends EastType
Textends DictType<StringType, NoInfer>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the dictionary
keyExpression<T["value"]["key"]>the Expression for the key to insert
valueEastFunction<V>the Expression for the value to insert

Returns

InsertFunction<T>

Example

Insert(dict, key, value)

Insert<T>(collection, key): InsertFunction<T>

Return a set where key has been inserted into collection.

Note: the input collection is unmodified (you need to use the return value)

Type parameters

NameType
Textends SetType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the set
keyExpression<T["value"]>the Expression for the key to insert

Returns

InsertFunction<T>

Example

Insert(set, key)

Insert<V, T>(collection, key, value): InsertFunction<T>

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)

Type parameters

NameType
Vextends EastType
Textends ArrayType<NoInfer>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the array
key"first" | "last"must be "first" or "last"
valueEastFunction<V>the Expression for the value to insert

Returns

InsertFunction<T>

Example

Insert(array, "last", value)

Intersect

Intersect<T, U>(first, second): IntersectFunction<T>

Return a set which is the intersection of first and second.

Type parameters

NameType
Textends SetType
Uextends SetType

Parameters

NameTypeDescription
firstEastFunction<T>the Expression for the first set
secondEastFunction<U>the Expression for the second set

Returns

IntersectFunction<T>

Example

Intersect(set1, set2)

Keys

Keys<T>(dict): KeysFunction<

SetType<T["value"]["key"]>>

Return the set of keys of dict.

Type parameters

NameType
Textends DictType

Parameters

NameTypeDescription
dictEastFunction<T>the Expression for the dictionary

Returns

KeysFunction<

SetType<T["value"]["key"]>>

Example

 // ...
// Given a dictionary from product quantities to price, get the set of product ids
ProductIds: Keys(Variable("ProductQuantities", DictType(IntegerType))),
// ...

Less

Less<T>(first, second): EastFunction<

BooleanType>

Compare two values and return true if the first is less than the second, or false otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if cost is less than a price
IsProfitable: Less(
Variable('Cost', FloatType),
Variable('Price', FloatType)
),
// ...

LessEqual

LessEqual<T>(first, second): EastFunction<

BooleanType>

Compare two values and return true if the first is less than or equal to the second, or false otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if purchase price is less than or equal to bank balance
CanPurchase: LessEqual(
Variable('Price', FloatType),
Variable('Balance', FloatType)
),
// ...

Let

Let<U, F>(value, expression): EastFunction<ReturnType<F>["type"]>

Defines a new variable in scope that can be accessed by the inner expression.

Type parameters

NameType
Uextends EastType
Fextends (variable: Variable<U>) => EastFunction

Parameters

NameTypeDescription
valueEastFunction<U>The value to assign to the new variable
expressionFA JavaScript function that returns an Expression to evaluate given the new variable in scope

Returns

EastFunction<ReturnType<F>["type"]>

Example

 // ...
// if name is null, replace with 'Unknown' string
Wage: Let(
Max(0, Subtract(Variable("Hours", FloatType), 8),
overtime => Add(
Multiply(
Variable("NormalRate", FloatType),
Subtract(Variable("Hours", FloatType), overtime)
),
Multiply(
Variable("OvertimeRate", FloatType),
overtime
)
)
),
// ...

Log

Log<T>(value): EastFunction<T>

Return the natural logarithm of a number (base e).

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to find the natural logarithm of

Returns

EastFunction<T>

Example

 // ...
// transform a positive variable into a logarithmic scale
XLog: Log(Variable('X', FloatType)),
// ...

LowerCase

LowerCase<T>(value): EastFunction<T>

Return a string containing only lowercase characters.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression with the input string

Returns

EastFunction<T>

Example

LowerCase(string)

MapDict

MapDict<T, U>(collection, value): MapValuesFunction<

DictType<T["value"], ReturnType<U>["type"]>>

Return a dictionary mapping the keys of a set through a function. The output keys match the input set.

Type parameters

NameType
Textends SetType
Uextends (key: Variable<T["value"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input set
valueUa function from the input key to an Expression to calculate the output value

Returns

MapValuesFunction<

DictType<T["value"], ReturnType<U>["type"]>>

Deprecated

use ToDict instead

Example

// ...
// Create full names for each of a set of employees
SomeEmployeeNames: MapDict(
Variable("SomeEmployeeIds", SetType<StringType>),
employeeId => StringJoin`${Get(Variable("EmployeeFirstNames", DictType(StringType)), employeeId)} ${Get(Variable("EmployeeLastNames", DictType(StringType)), employeeId)}`,
),
// ...

MapDict<T, U>(collection, value): MapValuesFunction<

DictType<T["value"]["key"], ReturnType<U>["type"]>>

Return a dictionary mapping the values of a dictionary through a function. The output keys match the keys of the input dictionary.

Type parameters

NameType
Textends DictType
Uextends (value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input dictionary
valueUa function from the input value and key to an Expression to calculate the output value

Returns

MapValuesFunction<

DictType<T["value"]["key"], ReturnType<U>["type"]>>

Deprecated

use ToDict instead

Example

// ...
// 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
)
)
)
// ...

Match

Match<Variants, Fs>(input, functions, defaultValue?): MergeTypes<{ [Tag in keyof Variants]: ReturnType<Fs[Tag]>["type"] }> extends never ? unknown : { ast_type: "Match" ; functions: Record<string, EastFunction> ; input: EastFunction<

VariantType> ; type: MergeTypes<{ [Tag in keyof Variants]: ReturnType<Fs[Tag]>["type"] }> ; value: string }

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.

Type parameters

NameType
Variantsextends Record<string, EastType>
Fsextends { [K in string | number | symbol]: Function }

Parameters

NameTypeDescription
inputEastFunction<VariantType<Variants>>the EastFunction for the input variant
functionsFsa function returning an EastFunction for each possible case or tag of the input variant
defaultValue?EastFunctionan optional EastFunction for any possible case or tag not listed in functions

Returns

MergeTypes<{ [Tag in keyof Variants]: ReturnType<Fs[Tag]>["type"] }> extends never ? unknown : { ast_type: "Match" ; functions: Record<string, EastFunction> ; input: EastFunction<

VariantType> ; type: MergeTypes<{ [Tag in keyof Variants]: ReturnType<Fs[Tag]>["type"] }> ; value: string }

See

Variant

Example

// ...
// 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: _ => "####"
},
)
// ...

Millisecond

Millisecond<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole milliseconds elapsed since the start of the second (0 - 999).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


Minute

Minute<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole minutes elapsed since the start of the hour (0 - 59).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


Modulo

Modulo<T>(first, second): EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>

Find the remainder when deviding first by second.

Type parameters

NameType
Textends IntegerType

Parameters

NameTypeDescription
firstnumberthe initial Expression to divide
secondEastFunction<T>the Expression to divide by

Returns

EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>

Example

 // ...
// return true if X is an even integer, or false if X is an odd integer
IsEven: Equal(
Modulo(
Variable('X', IntegerType),
2n
),
0n
),
// ...

Month

Month<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the month number of the year (January = 1, ..., December = 12).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


Multiply

Multiply<T, U>(first, second): EastFunction<T>

Multiply first by second.

Type parameters

NameType
Textends IntegerType | FloatType
Uextends number | bigint

Parameters

NameTypeDescription
firstUthe first Expression to multiply
secondEastFunction<T>the second Expression to multiply

Returns

EastFunction<T>

Example

 // ...
// return the total price of a quantity of products with a given unit price
TotalPrice: Multiply(
Variable('UnitPrice', FloatType),
Variable('Quantity', FloatType)
),
// return the number of calendar days in NumberOfWeeks
NumberOfDays: Multiply(
Variable('NumberOfWeeks', IntegerType),
7n
),
// ...

NewArray

NewArray<T>(value_type, values?): NewArrayFunction<

ArrayType<T>>

Construct an new array with the given values.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
value_typeTthe EastType the values of the array will be
values?Expression<NoInfer>[]a list of Expressions to insert as values into the new array (optional)

Returns

NewArrayFunction<

ArrayType<T>>

Example

// create a new empty array that can contain strings
NewArray(StringType)
// create a new array containing ["a", "b"]
NewArray(StringType, [Const("a"), Const("b")])

NewDict

NewDict<K, T>(key_type, value_type, keys?, values?): NewDictFunction<

DictType<K, T>>

Construct an new dictionary with the given keys and values.

Type parameters

NameType
Kextends StringType
Textends EastType

Parameters

NameTypeDefault valueDescription
key_typeKundefinedthe EastType the keys of the dictionary will be
value_typeTundefinedthe EastType the values of the dictionary will be
keysExpression<K>[][]an array of Expressions to insert as keys into the new dictionary (optional)
valuesExpression<NoInfer>[][]an array of Expressions to insert as values into the new dictionary (must be the same length as keys) (optional)

Returns

NewDictFunction<

DictType<K, T>>

Example

// 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)])

NewSet

NewSet<T>(key_type, keys?): NewSetFunction<

SetType<T>>

Construct a new set with given values.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
key_typeTthe EastType of the elements of the set
keys?Iterable<Expression<StringType>>a list of Expressions to insert as keys into the new set (optional)

Returns

NewSetFunction<

SetType<T>>

Example

// create a new empty set that can contain strings
NewSet(StringType)
// create a new set containing ["a", "b"]
NewSet(StringType, [Const("a"), Const("b")])

Not

Not<T>(value): EastFunction<T>

Return true if value is false, or false otherwise.

Type parameters

NameType
Textends BooleanType

Parameters

NameTypeDescription
valueExpression<T>the Expression to apply

Returns

EastFunction<T>

Example

 // ...
NotActive: Not(Variable('Active', BooleanType)),
// ...

NotEqual

NotEqual<T>(first, second): EastFunction<

BooleanType>

Compare two values and return false if equal, or true otherwise.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
firstEastFunction<T>the first Expression to compare
secondValueTypeOf<T>the second Expression to compare

Returns

EastFunction<

BooleanType>

Example

 // ...
// return true if an employee isn't a "Site Worker"
IsNotSiteWorker: NotEqual(
Variable('EmployeeCategory', StringType),
Const("Site Worker")
),
// ...

OnlyKey

OnlyKey<T>(dict): OnlyKeyFunction<

Nullable<T["value"]["key"]>>

Return the only key of dict, or else null if it has zero or more than two elements.

Type parameters

NameType
Textends DictType

Parameters

NameTypeDescription
dictEastFunction<T>the Expression for the dictionary

Returns

OnlyKeyFunction<

Nullable<T["value"]["key"]>>


Or

Or(): EastFunction<

BooleanType>

Return false if all values are false, or true otherwise.

Returns

EastFunction<

BooleanType>

Example

 // ...
// set an employee availability to true if they are a "Site Worker" OR they started more than 6 months ago
Available: Or(
Equal(
Variable('EmployeeCategory', StringType),
Const("Site Worker")
),
Greater(
Duration(
Variable('StartDate', DateTimeType),
Variable('ContractDate', DateTimeType),
'month'
),
6
)
),
// ...

Parse

Parse(type, from, format): EastFunction<

DateTimeType>

Parse an input string into an East value, using an optional format schema. The reverse of

Print.

Parameters

NameTypeDescription
typeDateTimeType-
fromEastFunction<StringType>the string Expression to parse
formatstringthe format to expect (optional)

Returns

EastFunction<

DateTimeType>

Example

Parse(IntegerType, integer_string)
Parse(DateTimeType, datetime_string) // defaults to ISO 8601
Parse(DateTimeType, date_string, 'DD-MM-YYYY') // specify a custom datetime format

Pow

Pow<T>(first, second): EastFunction<T>

Return first to the power of second, first ^ second.

Type parameters

NameType
Textends FloatType

Parameters

NameType
firstEastFunction<T>
secondnumber

Returns

EastFunction<T>

Example

 // ...
// find the cube root of X
Y: Pow(Variable('X', FloatType), 1/3),
// ...

Print

Print<T>(value, format?): EastFunction<

StringType>

Print a value to a string (with an optional format string).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueExpression<T>the Expression to print
format?stringthe format to apply

Returns

EastFunction<

StringType>

Example

 // ...
// print a date to string in a specific format
DateString: Print(Variable('Date', DateTimeType), 'DD-MM-YYYY'),
// ...

RandomKey

RandomKey<T>(collection, def?): RandomKeyFunction<

IntegerType>

Return a random key drawn from an array, dictionary or set.

Type parameters

NameType
Textends ArrayType

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for collection to sample keys from
def?Expression<IntegerType>an optional Expression for the default value to return if the collection is empty

Returns

RandomKeyFunction<

IntegerType>

Example

 // ...
// draw a random string "a", "b" or "c"
x: RandomKey(Const(new Set(["a", "b", "c"]))),
// ...

RandomNormal

RandomNormal(): RandomNormalFunction<

FloatType>

Return a random float drawn from a normal (Gaussian) distribution with mean 0.0 and standard deviation 1.0.

Returns

RandomNormalFunction<

FloatType>

Example

 // ...
// create a random float from a normal distribution
x: RandomNormal(),
// ...

RandomRange

RandomRange(min, max): RandomRangeFunction<

IntegerType>

Return a random integer between min and max (inclusive).

Parameters

NameTypeDescription
minbigint | EastFunction<IntegerType>the Expression for the minimum value to return
maxbigint | EastFunction<IntegerType>the Expression for the maximum value to return

Returns

RandomRangeFunction<

IntegerType>

Example

 // ...
// create a random integer between zero and one
x: RandomRange(0n, 10n),
// ...

RandomUniform

RandomUniform(): RandomUniformFunction<

FloatType>

Return a random float greater or equal to 0.0 and less than 1.0.

Returns

RandomUniformFunction<

FloatType>

Example

 // ...
// create a random float between zero and one
x: RandomUniform(),
// ...

RandomUniform(min, max): EastFunction<

FloatType>

Return a random float greater or equal to min and less than max.

Parameters

NameType
minnumber | EastFunction<FloatType>
maxnumber | EastFunction<FloatType>

Returns

EastFunction<

FloatType>

Example

 // ...
// create a random float between 1.0 and 10.0
x: RandomUniform(1.0, 10.0),
// ...

RandomValue

RandomValue<T>(collection, def?): RandomValueFunction<T["value"]>

Return a random value drawn from an array or dictionary.

Type parameters

NameType
Textends ArrayType

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for collection to sample values from
def?Expression<T["value"]>an optional Expression for the default value to return if the collection is empty

Returns

RandomValueFunction<T["value"]>

Example

 // ...
// draw a random string "a", "b" or "c"
x: RandomValue(Const(["a", "b", "c"])),
// ...

RandomWeightedKey

RandomWeightedKey<T>(collection, def?): RandomWeightedKeyFunction<

IntegerType>

Return a random key drawn from an array or dictionary with non-negative float values representing the relative probability of different keys.

Type parameters

NameType
Textends ArrayType<FloatType>

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for collection to sample keys from
def?Expression<IntegerType>an optional Expression for the default value to return if the collection is empty

Returns

RandomWeightedKeyFunction<

IntegerType>

Example

 // ...
// draw a random string "a", "b" or "c"
x: RandomKey(Const(new Set(["a", "b", "c"]))),
// ...

Range

Range(start, stop): RangeFunction<

ArrayType<IntegerType>>

Construct an array with a contiguous range of integers, [start, start+1n, ..., stop-1n, stop].

The range always includes both start and stop, unless start is greater than stop in which case the output is an empty array.

Parameters

NameTypeDescription
startExpression<IntegerType>an Expression for the first integer.
stopExpression<IntegerType>an Expression for the first integer.

Returns

RangeFunction<

ArrayType<IntegerType>>

Example

Range(1, Variable("n", IntegerType))

Reduce

Reduce<T, I, R>(collection, reducer, initial): ReduceFunction<ReturnType<R>["type"] & I["type"]>

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.

Type parameters

NameType
Textends ArrayType
Iextends EastFunction
Rextends (previous: Variable<I["type"]>, value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input collection to be reduced over
reducerR & ReturnType<R>["type"] & I["type"] extends never ? never : unknowna function of the previous value and input value and key variables returning an Expression giving the next value of the reduction *
initialIan Expression for the initial value of the reduction

Returns

ReduceFunction<ReturnType<R>["type"] & I["type"]>

Example

// To add up all the values in an array of integers
Reduce(
array,
(previous, value) => Add(previous, value),
Const(0n)
)

Reduce<T, I, R>(collection, reducer, initial): ReduceFunction<ReturnType<R>["type"] & I["type"]>

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.

Type parameters

NameType
Textends SetType
Iextends EastFunction
Rextends (previous: Variable<I["type"]>, key: Variable<T["value"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input collection to be reduced over
reducerR & ReturnType<R>["type"] & I["type"] extends never ? never : unknowna function of the previous value and input key variables returning an Expression giving the next value of the reduction
initialIan Expression for the initial value of the reduction

Returns

ReduceFunction<ReturnType<R>["type"] & I["type"]>

The final output of reducer, or else initial for empty collections

Example

// 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)
)

Reduce<T, I, R>(collection, reducer, initial): ReduceFunction<ReturnType<R>["type"] & I["type"]>

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.

Type parameters

NameType
Textends DictType
Iextends EastFunction
Rextends (previous: Variable<I["type"]>, value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input collection to be reduced over
reducerR & ReturnType<R>["type"] & I["type"] extends never ? never : unknowna function of the previous value and input value and key variables returning an Expression giving the next value of the reduction
initialIan Expression for the initial value of the reduction

Returns

ReduceFunction<ReturnType<R>["type"] & I["type"]>

The final output of reducer, or else initial for empty collections

Example

// To add up all the values in a dictionary of integers
Reduce(

dict,
(previous, value) => Add(previous, value),
Const(0n)
)

RegexContains

RegexContains<T>(value, search, flags?): EastFunction<T extends

NullType ? Nullable<BooleanType> : BooleanType>

Return true if value matches the regular expression search string, or false otherwise.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDefault valueDescription
valueEastFunction<T>undefinedthe Expression with the string to modify
searchstringundefinedthe (fixed) regular expression search string to search for
flagsstring'i'the regular expression flags to apply (default 'i' for case insensitive)

Returns

EastFunction<T extends

NullType ? Nullable<BooleanType> : BooleanType>

Example

 // ...
// Infer if product is a subscription product based on the
// presence of 'subscription' in the product's name
ProductIsSubscription: RegexContains(
Variable("ProductName", StringType),
'subscription'
),
// ...

RegexReplace

RegexReplace<T>(value, search, replace, flags?): EastFunction<T>

Return a string where value's matches to the regular expression search string are replaced with value of replace.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDefault valueDescription
valueEastFunction<T>undefinedthe Expression with the string to modify
searchstringundefinedthe (fixed) regular expressionsearch string to search for
replaceExpression<StringType>undefinedthe Expression for the string to replace matches with
flagsstring'g'the regular expression flags to apply (default 'g' for global, also 'i' for case insensitive)

Returns

EastFunction<T>

Example

 // ...
// extract the part of the string before the colon :
FirstPart: RegexReplace(
Variable("ComplexString", StringType),
'.*:(.+)',
'$1'
),
// ...

Repeat

Repeat<T>(value, n): EastFunction<T>

Return a string repeated a given number of times.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for string
nEastFunction<IntegerType>the Expression for the number of repetitions

Returns

EastFunction<T>

Remarks

if n is negative, the empty string is returned.

Example

 // ...
// create a string containing six zeros
SixZeros: Repeat(Const("0"), Const(6n)),
// ...

Round

Round<T>(value, rounding_mode, unit): RoundFunction<T>

Round datetime value to a whole time unit ("year", "month", "week", "day", "hour", "minute", "second"), using rounding_mode of "nearest", "floor" (round down) or "ceiling" (round up).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to round
rounding_modeRoundingMode'nearest', 'floor' (always round down) or 'ceiling' (always round up)
unitTimeUnit | CalendarUnit'year', 'month', 'week', 'day', 'hour', 'minute' or 'second'

Returns

RoundFunction<T>

Example

 // ...
// return the instant at the beginning of the week
WholeHoursWorked: Round(
Variable('Date', DateTimeType),
'floor',
'week'
),
// ...

Round<T>(value, rounding_mode, type): RoundFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Round number value to an integer, using rounding_mode of "nearest" (default), "floor" (round down) or "ceiling" (round up).

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to round
rounding_modeRoundingMode'nearest', 'floor' (always round down) or 'ceiling' (always round up)
type"integer"-

Returns

RoundFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Example

 // ...
// return the number of whole hours worked on a shift (rounded down)
WholeHoursWorked: Round(
Variable('HoursWorked', FloatType),
'floor',
'integer'
),
// ...

Round<T>(value, rounding_mode?, type?): RoundFunction<T>

Round number value to a whole number, using rounding_mode of "nearest" (default), "floor" (round down) or "ceiling" (round up).

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to round
rounding_mode?RoundingMode'nearest', 'floor' (always round down) or 'ceiling' (always round up)
type?"float"-

Returns

RoundFunction<T>

Example

 // ...
// return the quantity rounded to the nearest whole number
RoundedQuantity: Round(
Variable('Quantity', FloatType),
'nearest'
),
// ...

RoundPrecision

RoundPrecision<T>(value, significant_digits): EastFunction<T>

Round the number to the specified number of significant digits, e.g. 1234.5 -> 1200.0.

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to round
significant_digitsnumbernumber of significant digits to keep

Returns

EastFunction<T>

RoundPrecision<T>(value, significant_digits): EastFunction<T>

Round the integer to the specified number of significant digits, e.g. 1234 -> 1200.

Type parameters

NameType
Textends IntegerType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to round
significant_digitsnumbernumber of significant digits to keep

Returns

EastFunction<T>


Second

Second<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole seconds elapsed since the start of the minute (0 - 59).

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


SetDiff

SetDiff<T, U>(first, second): SetDiffFunction<T>

Return a set which is the set difference of first and second.

Type parameters

NameType
Textends SetType
Uextends SetType

Parameters

NameTypeDescription
firstEastFunction<T>the Expression for the first set
secondEastFunction<U>the Expression for the second set

Returns

SetDiffFunction<T>

Example

SetDiff(set1, set2)

Sin

Sin<T>(value): EastFunction<T>

Return the sine of a number. The input is specified in radians.

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for the angle

Returns

EastFunction<T>

Example

 // ...
// calculate the sine of an angle
sin_x: Sin(x),
// ...

Size

Size<T>(collection): SizeFunction<

IntegerType>

Get the number of elements in a collection.

Type parameters

NameType
Textends StringType | BlobType | SetType | ArrayType | DictType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the array, dictionary or set

Returns

SizeFunction<

IntegerType>

Example

 // ...
// Get the number of employees on a shift
NumberOfShiftEmployees: Size(
Variable("ShiftEmployeeIds", SetType<StringType>),
),
// ...

Sort

Sort<T, IsLess>(collection, isless?): SortFunction<T>

Sort an array in place, according an ordering defined by the comparison function isless. Primitive types will be sorted automatically according to Less.

Type parameters

NameType
Textends ArrayType
IsLessextends (first: Variable<T["value"]>, second: Variable<T["value"]>) => EastFunction<BooleanType>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input array
isless?IsLessa function from the first and second value to an Expression to calculate whether first is smaller than second (defaults to Less)

Returns

SortFunction<T>

Example

// ...
// Sort an array of datetimes into ascending order
AscendingDates: Sort(array_of_dates)
// Sort an array of datetimes into descending order
DescendingDates: Sort(array_of_dates, Greater)
// ...

Sqrt

Sqrt<T>(value): EastFunction<T>

Return the square root of a number.

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to find the square root of

Returns

EastFunction<T>

Example

 // ...
// return the quantity rounded to the nearest whole number
StandardDeviation: Sqrt(Variable('Variance', FloatType)),
// ...

Sqrt<T>(value): EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>

Return the square root of an integer (returning a floating-point number).

Type parameters

NameType
Textends IntegerType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression to find the square root of

Returns

EastFunction<T extends

NullType ? Nullable<FloatType> : FloatType>


StringJoin

StringJoin(values, seperator?, ...args): StringJoinFunction<

StringType>

Return a string concatenating all the values strings with the optional seperator. Also able to be used as a tagged template string literal.

Parameters

NameTypeDefault valueDescription
valuesExpression[] | Record<string, Expression> | TemplateStringsArrayundefinedthe Expression containing collection of strings
seperatorExpression""the string to place between consecutive values (defaults to "")
...argsExpression[]undefined-

Returns

StringJoinFunction<

StringType>

Example

StringJoin`There are ${Variable("qty", IntegerType)} items`

is equivalent to:

StringJoin(['There are ', Variable("qty", IntegerType), ' items'])

Example

 // ...
// create string with a comma seperated list of employee names from an array of employee names strings
EmployeeNamesString: StringJoin(
Variable(EmployeeNames, ArrayType<StringType>),
', ']
)
// ...

Struct

Struct<T>(fields): StructFunction<{ type: "Struct" ; value: { [K in keyof T]: ExpressionTypeOf<T[K]> } }>

Construct a struct from an expressions for each field.

Type parameters

NameType
Textends Record<string, Expression<EastType>>

Parameters

NameTypeDescription
fieldsTa record of Expressions defining the struct

Returns

StructFunction<{ type: "Struct" ; value: { [K in keyof T]: ExpressionTypeOf<T[K]> } }>

See

GetField

Example

// ...
// Create an aggregate struct with product data
ProductData: Struct({
Id: Variable("ProductId", StringType),
Name: Variable("ProductName", StringType),
UnitPrice: Variable("ProductPrice", FloatType),
StockLevel: Variable("ProductStockLevel", IntegerType),
StockTakeDate: Variable("ProductStockTakeDate", DateTimeType),
}),
// ...

SubsetEqual

SubsetEqual<T, U>(first, second): SubsetEqualFunction<

BooleanType>

Return true if the first set is a subset, or equal to, the second set.

Type parameters

NameType
Textends SetType
Uextends SetType

Parameters

NameTypeDescription
firstEastFunction<T>the Expression for the first set
secondEastFunction<U>the Expression for the second set

Returns

SubsetEqualFunction<

BooleanType>

Example

SubsetEqual(set1, set2)

Substring

Substring<T>(value, start, stop): EastFunction<T>

Return a substring of value between the characters start and stop.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for string
startnumberthe Expression giving the index of the first character to keep (starting at 0)
stopnumberthe Expression giving the index after the final character to keep

Returns

EastFunction<T>

Example

 // ...
// extract the first two characters of Id
Prefix: Substring(Variable('Id', StringType), 0, 2),
// ...

Subtract

Subtract<T, U>(first, second): EastFunction<T>

Subtract second from first. These can either be integer of float expressions. Combining float with integer will result in a float.

Type parameters

NameType
Textends IntegerType | FloatType
Uextends number | bigint

Parameters

NameTypeDescription
firstUthe Expression to subtract from
secondEastFunction<T>the Expression amount to subtract

Returns

EastFunction<T>

Example

 // ...
// return the bank balance after a purchase is made
NewBalance: Subtract(
Variable('Balance', FloatType),
Variable('PurchaseTotal', FloatType)
),
// return the number of stock after a quantity is sold
NewStockLevel: Subtract(
Variable('StockLevel', IntegerType),
Variable('SaleQuantity', IntegerType)
),
// ...

SubtractDuration

SubtractDuration<T, U>(datetime, duration, unit): EastFunction<T extends

NullType ? Nullable<DateTimeType> : U extends NullType ? Nullable<DateTimeType> : DateTimeType>

Subtract the duration (in the given time unit) from datetime.

Type parameters

NameType
Textends DateTimeType
Uextends FloatType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for the initial datetime
durationExpression<U>the Expression for duration
unitTimeUnitthe TimeUnit of duration ('millisecond', 'second', 'minute', 'hour', 'day' or 'week')

Returns

EastFunction<T extends

NullType ? Nullable<DateTimeType> : U extends NullType ? Nullable<DateTimeType> : DateTimeType>

Example

 // ...
// return the date payment is due for an invoice according to the invoice terms
DueDate: SubtractDuration(
Variable('PurchaseDate', DateTimeType),
Variable('InvoiceTermDays', FloatType),
'day'
),
// ...

SymDiff

SymDiff<T, U>(first, second): SymDiffFunction<T>

Return a set which is the symmetric difference of first and second.

Type parameters

NameType
Textends SetType
Uextends SetType

Parameters

NameTypeDescription
firstEastFunction<T>the Expression for the first set
secondEastFunction<U>the Expression for the second set

Returns

SymDiffFunction<T>

Example

SymDiff(set1, set2)

Tan

Tan<T>(value): EastFunction<T>

Return the tangent of a number. The input is specified in radians.

Type parameters

NameType
Textends FloatType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression for the angle

Returns

EastFunction<T>

Example

 // ...
// calculate the tangent of an angle
tan_x: Tan(x),
// ...

TimeZoneConvert

TimeZoneConvert<T>(datetime, input_timezone, output_timezone): EastFunction<T>

Convert the datetime from input_timezone to output_timezone.

Note: all datetimes in East are plain (or "naive") datetimes and conversion should take place using this function. Absolute durations should be calculated in UTC (zone 'Etc/UTC') to account for e.g. day-light-saving changeovers. The list of IANA timezone strings can be found at

https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for the input datetime
input_timezonestring | EastFunction<StringType & { nullable?: undefined }>the Expression for the input's timezone (as an IANA timezone string)
output_timezonestring | EastFunction<StringType & { nullable?: undefined }>the Expression for the output's timezone (as an IANA timezone string)

Returns

EastFunction<T>

Example

 // ...
// convert the UTC time into Sydney, Australia time
LocalTime: ConvertTimeZone(
Variable('UtcTime', DateTimeType),
'Etc/UTC',
'Australia/Sydney'
),
// ...

ToArray

ToArray<T, U>(collection, value): ToArrayFunction<

ArrayType<U>>

Return an array where each output value is calculated from each element of the input collection.

Type parameters

NameType
Textends SetType
Uextends EastType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input set
value(key: Variable<T["value"]>) => EastFunction<U> | () => EastFunction<U>a function from input key to an Expression to calculate the output value

Returns

ToArrayFunction<

ArrayType<U>>

Example

// convert a set to an array
ToArray(set)
// create an array by applying the UpperCase function to each element of the set
ToArray(set, x => UpperCase(x))

ToArray<T, U>(collection, value): ToArrayFunction<

ArrayType<U>>

Return an array where each output value is calculated from each element of the input collection.

Type parameters

NameType
Textends DictType
Uextends EastType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input dictionary
value(value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction<U>a function from input value and key to an Expression to calculate the output value

Returns

ToArrayFunction<

ArrayType<U>>

Example

// create an array from the values of a dictionary
ToArray(dict)
// create an array by applying the UpperCase function to keys of a dictionary
ToArray(dict, (value, key) => UpperCase(key))

ToArray<T, U>(collection, value): ToArrayFunction<

ArrayType<U>>

Return an array where each output value is calculated from each element of the input collection.

Type parameters

NameType
Textends ArrayType
Uextends EastType

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input array
value(value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction<U>a function from input value and key to an Expression to calculate the output value

Returns

ToArrayFunction<

ArrayType<U>>

Example

// create a new array by applying the UpperCase function to each element of the input
ToArray(array, x => UpperCase(x))

ToCsv

ToCsv<T>(value, printers?, options?): ToCsvFunction<

BlobType>

Return a blob containing a CSV encoding of an array of structs.

Type parameters

NameType
Textends ArrayType<StructType>

Parameters

NameTypeDescription
valueEastFunction<T>the Expression with the value to encode as CSV
printers{ [K in string | number | symbol]?: Function }an object containing functions returning Expressions to print each field (e.g. to format a date-time)
optionsPartial<ToCsvOptions>provide options for formatting the CSV files (such as delimeters, null sentinels, and headers)

Returns

ToCsvFunction<

BlobType>

Example

ToCsv(
array_of_structs,
{ date: x => Print(x, "YYYY-MM-DD") },
{ nullString: "NA" }
)

ToDateTime

ToDateTime(value, format?): EastFunction<

Nullable<DateTimeType>>

Construct a datetime value from a string, with optional format.

Parameters

NameTypeDescription
valueEastFunction<StringType>the string Expression to parse
format?stringthe format string (by default it expects ISO-8601, e.g. 'YYYY-MM-DDThh:mm:ss.sssZ')

Returns

EastFunction<

Nullable<DateTimeType>>

Example

 // ...
// parse the date from the US-formated date string
Date: ToDateTime('DateString', 'M-D-YYYY'),
// ...

ToDict

ToDict<T, VOut>(collection, value): ToDictFunction<

DictType<T["value"], ReturnType<VOut>["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.

Type parameters

NameType
Textends SetType
VOutextends (key: Variable<T["value"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input set
valueVOuta function from the input key (and previous value) to an Expression to calculate the output value

Returns

ToDictFunction<

DictType<T["value"], ReturnType<VOut>["type"]>>

Example

// create a new dictionary mapping the keys of a set to their uppercase values
ToDict(
set,
x => UpperCase(x),
x => x,
)

ToDict<T, VOut, KOut>(collection, value, key): ToDictFunction<

DictType<ReturnType<KOut>["type"], ReturnType<VOut>["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.

Type parameters

NameType
Textends ArrayType
VOutextends (value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction
KOutextends (value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction<StringType>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input array
valueVOuta function from the input value and key (and previous value) to an Expression to calculate the output value
keyKOuta function from the input value and key to an Expression to calculate the output key

Returns

ToDictFunction<

DictType<ReturnType<KOut>["type"], ReturnType<VOut>["type"]>>

Example

// create a new dictionary mapping the elements of an array to their uppercase values
ToDict(
array,
x => UpperCase(x),
x => x,
)

ToDict<T, VOut>(collection, value): ToDictFunction<

DictType<T["value"]["key"], ReturnType<VOut>["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.

Type parameters

NameType
Textends DictType
VOutextends (value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the input dictionary
valueVOuta function from the input value and key (and previous value) to an Expression to calculate the output value

Returns

ToDictFunction<

DictType<T["value"]["key"], ReturnType<VOut>["type"]>>

Example

// create a new dictionary incrementing the integer values of the input dictionary
ToDict(
dict,
(value, key) => Add(value, 1n),
(value, key) => key,
)

ToJson

ToJson<T>(value): ToJsonFunction<

StringType>

Return a string containing a JSON encoding the East value (similar to JSON.stringify).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression with the value to encode as JSON

Returns

ToJsonFunction<

StringType>

Example

ToJson(value)

ToSet

ToSet<T, KOut>(collection, key): ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Return a set where each output key is calculated from elements of the input collection. Duplicate and null output keys are ignored.

Type parameters

NameType
Textends SetType
KOutextends (key: Variable<T["value"]>) => EastFunction<StringType>

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for the input set
keyKOuta function from input key to an Expression to calculate the output key

Returns

ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Example

// create a new set containing uppercase versions of the input elements
ToSet(set, x => UpperCase(x))

ToSet<T, KOut>(collection, key): ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Return a set where each output key is calculated from elements of the input collection. Duplicate and null output keys are ignored.

Type parameters

NameType
Textends DictType
KOutextends (value: Variable<T["value"]["value"]>, key: Variable<T["value"]["key"]>) => EastFunction<StringType>

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for the input dictionary
keyKOuta function from input value and key to an Expression to calculate the output key

Returns

ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Example

// create a new set containing uppercase versions of the keys of the dictionary
ToSet(dict, (value, key) => UpperCase(key))

ToSet<T, KOut>(collection, key): ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Return a set where each output key is calculated from elements of the input collection. Duplicate and null output keys are ignored.

Type parameters

NameType
Textends ArrayType
KOutextends (value: Variable<T["value"]>, key: Variable<IntegerType>) => EastFunction<StringType>

Parameters

NameTypeDescription
collectionEastFunction<T>the EastFunction for the input array
keyKOuta function from input value and key to an Expression to calculate the output key

Returns

ToSetFunction<

SetType<ReturnType<KOut>["type"]>>

Example

// create a new set containing the elements of the array (duplicates will be discarded)
ToSet(array)
// create a new set containing uppercase versions of the elements of the array
ToSet(array, x => UpperCase(x))

URIDecode

URIDecode(value): URIDecodeFunction<

StringType>

Decode a string from a compoment of a URI.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the URI string

Returns

URIDecodeFunction<

StringType>


URIEncode

URIEncode(value): URIEncodeFunction<

StringType>

Encode a string suitable for placing as a component inside a URI.

Parameters

NameTypeDescription
valueEastFunction<StringType>the Expression for the input string

Returns

URIEncodeFunction<

StringType>


Union

Union<T, U>(first, second): UnionFunction<T>

Return a set which is the union of first and second.

Type parameters

NameType
Textends SetType
Uextends SetType

Parameters

NameTypeDescription
firstEastFunction<T>the Expression for the first set
secondEastFunction<U>the Expression for the second set

Returns

UnionFunction<T>

Example

Union(set1, set2)

Update

Update<V, T>(collection, key, value): UpdateFunction<T>

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).

Type parameters

NameType
Vextends EastType
Textends ArrayType<NoInfer>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the array
keybigint | EastFunction<IntegerType>the Expression for the key (i.e. index) to update
valueEastFunction<V>the Expression for the value to update

Returns

UpdateFunction<T>

Example

Update(array, index, value)

Update<V, T>(collection, key, value): UpdateFunction<T>

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).

Type parameters

NameType
Vextends EastType
Textends DictType<StringType, NoInfer>

Parameters

NameTypeDescription
collectionEastFunction<T>the Expression for the dictionary
keystring | EastFunction<StringType>the Expression for the key to update
valueEastFunction<V>the Expression for the value to update

Returns

UpdateFunction<T>

Example

Update(dict, key, value)

UpperCase

UpperCase<T>(value): EastFunction<T>

Return a string containing only uppercase characters.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
valueEastFunction<T>the Expression with the input string

Returns

EastFunction<T>

Example

UpperCase(string)

Utf8Decode

Utf8Decode<T>(from): Utf8DecodeFunction<

StringType>

Return a blob containing a string encoded as a UTF8 bytestring.

Type parameters

NameType
Textends BlobType

Parameters

NameTypeDescription
fromEastFunction<T>the EastFunction of the string to encode

Returns

Utf8DecodeFunction<

StringType>

Example

 // ...
String: Utf8Decode(blob),
// ...

Utf8Encode

Utf8Encode<T>(from): Utf8EncodeFunction<

BlobType>

Return a blob containing a string encoded as a UTF8 bytestring.

Type parameters

NameType
Textends StringType

Parameters

NameTypeDescription
fromEastFunction<T>the EastFunction of the string to encode

Returns

Utf8EncodeFunction<

BlobType>

Example

 // ...
Blob: Utf8Encode(string),
// ...

Variant

Variant<Tag>(tag): VariantFunction<

VariantType<{ [K in Tag]: NullType }>>

Return an EastFunction that constructs a variant with a given case (or tag) and associated value.

Type parameters

NameType
Tagextends string

Parameters

NameType
tagTag

Returns

VariantFunction<

VariantType<{ [K in Tag]: NullType }>>

See

Match

Example

// ...
// 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"),
)
// ...

Year

Year<T>(datetime): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Return the number of whole years since 0AD.

Type parameters

NameType
Textends DateTimeType

Parameters

NameTypeDescription
datetimeEastFunction<T>the Expression for datetime

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>