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 EastFunctionType parameters
Name | Type |
---|---|
T | extends 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
Name | Type |
---|---|
T | extends IntegerType | FloatType |
U | extends number | bigint |
Parameters
Name | Type | Description |
---|---|---|
first | U | the first Expression to add |
second | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
U | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <T > | the Expression for the initial datetime |
duration | Expression <U > | the Expression for duration |
unit | TimeUnit | the 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
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type | Description |
---|---|---|
value | EastFunction <StringType > | the Expression for the input Base64 string |
Returns
Base64ToAsciiFunction
<
StringType
>
Base64ToHex
▸ Base64ToHex(value
): Base64ToHexFunction
<
StringType
>
Convert a Base64 string to hexadecimal encoding.
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value | ValueTypeOf <T > | the Value to declare |
type | T | - |
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
Name | Type |
---|---|
T | extends Value |
Parameters
Name | Type | Description |
---|---|---|
value | T | the 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
Name | Type | Description |
---|---|---|
from | EastFunction <Nullable <IntegerType >> | the Expression to convert |
type | Nullable <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
Name | Type | Description |
---|---|---|
from | EastFunction <Nullable <FloatType >> | the Expression to convert |
type | Nullable <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
type | T | the 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
Name | Type |
---|---|
T | extends DictType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the dictionary |
key | Expression <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
Name | Type |
---|---|
T | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the set |
key | Expression <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
Name | Type |
---|---|
T | extends ArrayType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends IntegerType | FloatType |
U | extends number | bigint |
Parameters
Name | Type | Description |
---|---|---|
first | U | the initial Expression to divide |
second | EastFunction <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
Type parameters
Name | Type |
---|---|
T | extends DateTimeType |
U | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
start | EastFunction <T > | the Expression for the initial datetime |
stop | EastFunction <U > | the Expression for the final datetime |
unit | TimeUnit | the 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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
Pred | extends (key : Variable <T ["value" ]>) => EastFunction <BooleanType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input set |
predicate | Pred | a 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
Name | Type |
---|---|
T | extends DictType |
Pred | extends (value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction <BooleanType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input dictionary |
predicate | Pred | a 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
Name | Type |
---|---|
T | extends ArrayType |
Pred | extends (value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction <BooleanType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input array |
predicate | Pred | a 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
Name | Type |
---|---|
T | extends ArrayType |
U | extends (value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction <VariantType <{ none : NullType ; some : EastType }>> |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input array |
value | U | a 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
Name | Type |
---|---|
T | extends SetType |
U | extends (key : Variable <T ["value" ]>) => EastFunction <VariantType <{ none : NullType ; some : StringType }>> |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input set |
value | U | a 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
Name | Type |
---|---|
T | extends DictType |
U | extends (value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction <VariantType <{ none : NullType ; some : EastType }>> |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input dictionary |
value | U | a 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
Name | Type |
---|---|
T | extends ArrayType <StructType > |
Parameters
Name | Type | Description |
---|---|---|
type | T | the EastType of the output to decode (column names should match the CSV file) |
value | EastFunction <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) |
options | Partial <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
Name | Type |
---|---|
U | extends StringType |
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
type | T | the EastType to decode to |
value | EastFunction <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
Name | Type |
---|---|
T | extends DictType |
D | extends EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the dictionary |
key | EastFunction <T ["value" ]["key" ]> | the Expression for the (string) key |
defaultValue | D & 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
Name | Type |
---|---|
T | extends ArrayType |
D | extends EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the array |
key | EastFunction <IntegerType > | the Expression for the (integer) key |
defaultValue | D & 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
Name | Type |
---|---|
T | extends StructType |
K | extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
struct | EastFunction <T > | the Expression for the input struct |
field | K | the name of field to fetch |
Returns
GetFieldFunction
<T
["value"
][K
]>
See
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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type | Description |
---|---|---|
value | EastFunction <StringType > | the Expression for the string to sign |
key | EastFunction <StringType > | the Expression for the HMAC key |
hash | HashType | the 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
Name | Type | Description |
---|---|---|
value | EastFunction <StringType > | the Expression for the string to hash |
hash | HashType | the 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
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
F1 | extends EastFunction |
F2 | extends EastFunction |
Parameters
Name | Type | Description |
---|---|---|
predicate | EastFunction <BooleanType > | the Expression to test |
x1 | F1 | the return value if predicate is true |
x2 | F2 & F1 ["type" ] & F2 ["type" ] extends never ? never : unknown | the 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
Name | Type |
---|---|
T | extends Nullable |
N | extends PrimitiveValue |
V | extends (x : Variable <NonNullable <T >>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
input | EastFunction <T > | the nullable Expression to test |
out_null | N | the return value if input is null |
out_value | V & EastTypeOf <N > & ReturnType <V >["type" ] extends never ? never : unknown | a 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
Name | Type |
---|---|
T | extends ArrayType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | - |
key | bigint | the 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
Name | Type |
---|---|
V | extends EastType |
T | extends DictType <StringType , NoInfer > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the dictionary |
key | Expression <T ["value" ]["key" ]> | the Expression for the key to insert |
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the set |
key | Expression <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
Name | Type |
---|---|
V | extends EastType |
T | extends ArrayType <NoInfer > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the array |
key | "first" | "last" | must be "first" or "last" |
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
U | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the Expression for the first set |
second | EastFunction <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
Name | Type |
---|---|
T | extends DictType |
Parameters
Name | Type | Description |
---|---|---|
dict | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type |
---|---|
U | extends EastType |
F | extends (variable : Variable <U >) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <U > | The value to assign to the new variable |
expression | F | A 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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
U | extends (key : Variable <T ["value" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input set |
value | U | a 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
Name | Type |
---|---|
T | extends DictType |
U | extends (value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input dictionary |
value | U | a 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
Name | Type |
---|---|
Variants | extends Record <string , EastType > |
Fs | extends { [K in string | number | symbol]: Function } |
Parameters
Name | Type | Description |
---|---|---|
input | EastFunction <VariantType <Variants >> | the EastFunction for the input variant |
functions | Fs | a function returning an EastFunction for each possible case or tag of the input variant |
defaultValue? | EastFunction | an 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
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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends IntegerType |
Parameters
Name | Type | Description |
---|---|---|
first | number | the initial Expression to divide |
second | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends IntegerType | FloatType |
U | extends number | bigint |
Parameters
Name | Type | Description |
---|---|---|
first | U | the first Expression to multiply |
second | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value_type | T | the 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
Name | Type |
---|---|
K | extends StringType |
T | extends EastType |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
key_type | K | undefined | the EastType the keys of the dictionary will be |
value_type | T | undefined | the EastType the values of the dictionary will be |
keys | Expression <K >[] | [] | an array of Expressions to insert as keys into the new dictionary (optional) |
values | Expression <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
key_type | T | the 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
Name | Type |
---|---|
T | extends BooleanType |
Parameters
Name | Type | Description |
---|---|---|
value | Expression <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the first Expression to compare |
second | ValueTypeOf <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
Name | Type |
---|---|
T | extends DictType |
Parameters
Name | Type | Description |
---|---|---|
dict | EastFunction <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
Name | Type | Description |
---|---|---|
type | DateTimeType | - |
from | EastFunction <StringType > | the string Expression to parse |
format | string | the 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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
first | EastFunction <T > |
second | number |
Returns
EastFunction
<T
>
Example
// ...
// find the cube root of X
Y: Pow(Variable('X', FloatType), 1/3),
// ...
▸ Print<T
>(value
, format?
): EastFunction
<
StringType
>
Print a value to a string (with an optional format string).
Type parameters
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value | Expression <T > | the Expression to print |
format? | string | the 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
Name | Type |
---|---|
T | extends ArrayType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type | Description |
---|---|---|
min | bigint | EastFunction <IntegerType > | the Expression for the minimum value to return |
max | bigint | 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
Name | Type |
---|---|
min | number | EastFunction <FloatType > |
max | number | 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
Name | Type |
---|---|
T | extends ArrayType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends ArrayType <FloatType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type | Description |
---|---|---|
start | Expression <IntegerType > | an Expression for the first integer. |
stop | Expression <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
Name | Type |
---|---|
T | extends ArrayType |
I | extends EastFunction |
R | extends (previous : Variable <I ["type" ]>, value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input collection to be reduced over |
reducer | R & ReturnType <R >["type" ] & I ["type" ] extends never ? never : unknown | a function of the previous value and input value and key variables returning an Expression giving the next value of the reduction * |
initial | I | an 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
Name | Type |
---|---|
T | extends SetType |
I | extends EastFunction |
R | extends (previous : Variable <I ["type" ]>, key : Variable <T ["value" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input collection to be reduced over |
reducer | R & ReturnType <R >["type" ] & I ["type" ] extends never ? never : unknown | a function of the previous value and input key variables returning an Expression giving the next value of the reduction |
initial | I | an 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
Name | Type |
---|---|
T | extends DictType |
I | extends EastFunction |
R | extends (previous : Variable <I ["type" ]>, value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input collection to be reduced over |
reducer | R & ReturnType <R >["type" ] & I ["type" ] extends never ? never : unknown | a function of the previous value and input value and key variables returning an Expression giving the next value of the reduction |
initial | I | an 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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | EastFunction <T > | undefined | the Expression with the string to modify |
search | string | undefined | the (fixed) regular expression search string to search for |
flags | string | '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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | EastFunction <T > | undefined | the Expression with the string to modify |
search | string | undefined | the (fixed) regular expressionsearch string to search for |
replace | Expression <StringType > | undefined | the Expression for the string to replace matches with |
flags | string | '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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression for string |
n | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression to round |
rounding_mode | RoundingMode | 'nearest', 'floor' (always round down) or 'ceiling' (always round up) |
unit | TimeUnit | 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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression to round |
rounding_mode | RoundingMode | '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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression to round |
significant_digits | number | number 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
Name | Type |
---|---|
T | extends IntegerType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression to round |
significant_digits | number | number 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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
U | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the Expression for the first set |
second | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends StringType | BlobType | SetType | ArrayType | DictType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends ArrayType |
IsLess | extends (first : Variable <T ["value" ]>, second : Variable <T ["value" ]>) => EastFunction <BooleanType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input array |
isless? | IsLess | a 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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends IntegerType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type | Default value | Description |
---|---|---|---|
values | Expression [] | Record <string , Expression > | TemplateStringsArray | undefined | the Expression containing collection of strings |
seperator | Expression | "" | the string to place between consecutive values (defaults to "") |
...args | Expression [] | 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
Name | Type |
---|---|
T | extends Record <string , Expression <EastType >> |
Parameters
Name | Type | Description |
---|---|---|
fields | T | a record of Expressions defining the struct |
Returns
StructFunction
<{ type
: "Struct"
; value
: { [K in keyof T]: ExpressionTypeOf<T[K]> } }>
See
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
Name | Type |
---|---|
T | extends SetType |
U | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the Expression for the first set |
second | EastFunction <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | the Expression for string |
start | number | the Expression giving the index of the first character to keep (starting at 0) |
stop | number | the 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
Name | Type |
---|---|
T | extends IntegerType | FloatType |
U | extends number | bigint |
Parameters
Name | Type | Description |
---|---|---|
first | U | the Expression to subtract from |
second | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
U | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <T > | the Expression for the initial datetime |
duration | Expression <U > | the Expression for duration |
unit | TimeUnit | the 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
Name | Type |
---|---|
T | extends SetType |
U | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the Expression for the first set |
second | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <T > | the Expression for the input datetime |
input_timezone | string | EastFunction <StringType & { nullable? : undefined }> | the Expression for the input's timezone (as an IANA timezone string) |
output_timezone | string | 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
Name | Type |
---|---|
T | extends SetType |
U | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends DictType |
U | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends ArrayType |
U | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends ArrayType <StructType > |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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) |
options | Partial <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
Name | Type | Description |
---|---|---|
value | EastFunction <StringType > | the string Expression to parse |
format? | string | the 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
Name | Type |
---|---|
T | extends SetType |
VOut | extends (key : Variable <T ["value" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input set |
value | VOut | a 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
Name | Type |
---|---|
T | extends ArrayType |
VOut | extends (value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction |
KOut | extends (value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction <StringType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input array |
value | VOut | a function from the input value and key (and previous value) to an Expression to calculate the output value |
key | KOut | a 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
Name | Type |
---|---|
T | extends DictType |
VOut | extends (value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the input dictionary |
value | VOut | a 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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
KOut | extends (key : Variable <T ["value" ]>) => EastFunction <StringType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the EastFunction for the input set |
key | KOut | a 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
Name | Type |
---|---|
T | extends DictType |
KOut | extends (value : Variable <T ["value" ]["value" ]>, key : Variable <T ["value" ]["key" ]>) => EastFunction <StringType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the EastFunction for the input dictionary |
key | KOut | a 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
Name | Type |
---|---|
T | extends ArrayType |
KOut | extends (value : Variable <T ["value" ]>, key : Variable <IntegerType >) => EastFunction <StringType > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the EastFunction for the input array |
key | KOut | a 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
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends SetType |
U | extends SetType |
Parameters
Name | Type | Description |
---|---|---|
first | EastFunction <T > | the Expression for the first set |
second | EastFunction <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
Name | Type |
---|---|
V | extends EastType |
T | extends ArrayType <NoInfer > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the array |
key | bigint | EastFunction <IntegerType > | the Expression for the key (i.e. index) to update |
value | EastFunction <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
Name | Type |
---|---|
V | extends EastType |
T | extends DictType <StringType , NoInfer > |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <T > | the Expression for the dictionary |
key | string | EastFunction <StringType > | the Expression for the key to update |
value | EastFunction <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends BlobType |
Parameters
Name | Type | Description |
---|---|---|
from | EastFunction <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
from | EastFunction <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
Name | Type |
---|---|
Tag | extends string |
Parameters
Name | Type |
---|---|
tag | Tag |
Returns
VariantFunction
<
VariantType
<{ [K in Tag]: NullType }>>
See
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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type | Description |
---|---|---|
datetime | EastFunction <T > | the Expression for datetime |
Returns
EastFunction
<T
extends
NullType
? Nullable
<IntegerType
> : IntegerType
>