Skip to main content

StdLib

The

StdLib module provides a set of standard libraries for common Expression patterns.

StdLib

OptionType

Ƭ OptionType<T>:

VariantType<{ none: NullType ; some: T }>

Return an EastType for the Option variant with cases "none" (indicating the lack of data) and "some" (indicating the presence of data).

This is an alias for VariantType({ none: NullType, some: type }).

Param

The EastType associated with the "some" case.

See

Some, Unwrap, None, MapOption.

Type parameters

NameType
Textends EastType = EastType

None

Const None: ConstFunction<

VariantType<{ none: NullType }>>

An EastFunction containing the "none" case of the Option variant. This is an alias for Const(none).

See

Some, Unwrap, MapOption, OptionType.


Abs

Abs(x): EastFunction<

IntegerType>

Return the absolute value of a number or integer

Expression.

Parameters

NameType
xExpression<IntegerType>

Returns

EastFunction<

IntegerType>


AddAll

AddAll(collection): EastFunction<

FloatType>

Add all collection values into a single float or integer

Expression.

Parameters

NameType
collectionEastFunction<ArrayType<FloatType>>

Returns

EastFunction<

FloatType>


AddDict

AddDict<T>(d1, d2): MapValuesFunction<

DictType<StringType, any>>

Add first to second where both are dictionaries.

Type parameters

NameType
Textends NumericType

Parameters

NameType
d1EastFunction<DictType<StringType, T>>
d2EastFunction<DictType<StringType, T>>

Returns

MapValuesFunction<

DictType<StringType, any>>

Remarks

Missing keys between first and second are assumed to have a value of 0.

Example

 // ...
// return the prices by dividing the total amounts by the qtys
NewBalance: AddDict(
Variable('InitialBalance', DictType(StringType, FloatType)),
Variable('Amount', DictType(StringType, FloatType))
),
// ...

Ceiling

Ceiling<T>(value, unit): EastFunction<T>

Round datetime value up to a whole time unit ("year", "month", "week", "day", "hour", "minute", "second").

Type parameters

NameType
Textends DateTimeType

Parameters

NameType
valueEastFunction<T>
unitTimeUnit | CalendarUnit

Returns

EastFunction<T>

Ceiling<T>(value, type?): EastFunction<T>

Round number value up to a whole number.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type?"float"

Returns

EastFunction<T>

Ceiling<T>(value, type?): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Round number value up to nearest integer.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type?"integer"

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


Compare

Compare<T>(a, b): EastFunction<

IntegerType>

Comparison function between two expressions.

Type parameters

NameType
Textends EastType

Parameters

NameType
aExpression<T>
bExpression<T>

Returns

EastFunction<

IntegerType>


ConvertFloatDict

ConvertFloatDict(dict): EastFunction<

DictType<StringType, IntegerType>>

Convert a float

DictType to an integer DictType.

Parameters

NameType
dictEastFunction<DictType<StringType, FloatType>>

Returns

EastFunction<

DictType<StringType, IntegerType>>


ConvertIntegerDict

ConvertIntegerDict(dict): EastFunction<

DictType<StringType, FloatType>>

Convert an integer

DictType to an float DictType.

Parameters

NameType
dictEastFunction<DictType<StringType, IntegerType>>

Returns

EastFunction<

DictType<StringType, FloatType>>


DateKey

DateKey(value, unit?): EastFunction<

StringType>

Convenience function to convert a datetime into a string for a key, rounding optional.

Parameters

NameType
valueEastFunction<DateTimeType>
unit?TimeUnit | CalendarUnit

Returns

EastFunction<

StringType>


DayInteger

DayInteger(day_name): GetFunction<

IntegerType>

Return a

Print function to convert a day of week Expression to a day of week name.

Parameters

NameType
day_nameEastFunction<StringType>

Returns

GetFunction<

IntegerType>


DayName

DayName(date): GetFunction<

StringType>

Return a

Print function to convert a datetime Expression to a day of week name.

Parameters

NameType
dateEastFunction<IntegerType | DateTimeType>

Returns

GetFunction<

StringType>


DayNameShort

DayNameShort(date): GetFunction<

StringType>

Return a

Print function to convert a datetime Expression to an abbreviated day of week name.

Parameters

NameType
dateEastFunction<IntegerType | DateTimeType>

Returns

GetFunction<

StringType>


FilterTag

FilterTag<T, Tag, K>(collection, tag): EastFunction<

DictType<K, T["value"][Tag]>>

Filter and map a collection (array or dictionary) of variants, keeping just one variant case (or tag) and unwrapping the associated data.

Type parameters

NameType
Textends VariantType
Tagextends string | number | symbol
Kextends StringType

Parameters

NameTypeDescription
collectionEastFunction<DictType<K, T>>an Expression for a collection of variants
tagTagthe variant case (or tag) to keep and unwrap

Returns

EastFunction<

DictType<K, T["value"][Tag]>>


Floor

Floor<T>(value, unit): EastFunction<T>

Round datetime value down to a whole time unit ("year", "month", "week", "day", "hour", "minute", "second").

Type parameters

NameType
Textends DateTimeType

Parameters

NameType
valueEastFunction<T>
unitTimeUnit | CalendarUnit

Returns

EastFunction<T>

Floor<T>(value, type): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Round number value down to nearest integer

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type"integer"

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Floor<T>(value, type?): EastFunction<T>

Round number value down to a whole number.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type?"float"

Returns

EastFunction<T>


GetTag

GetTag<Variants, Fs>(value): EastFunction<

StringType>

Returns a

StringType EastFunction for the tag of a VariantType EastFunction.

Type parameters

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

Parameters

NameTypeDescription
valueEastFunction<VariantType<Variants>>An EastFunction for the Option variant.

Returns

EastFunction<

StringType>


HasTag

HasTag<T, Tag>(value, tag): EastFunction<

BooleanType>

Returns a

BooleanType to determine if the tag of a VariantType EastFunction matches a supplied value.

Type parameters

NameType
Textends VariantType
Tagextends string | number | symbol

Parameters

NameTypeDescription
valueEastFunction<T>An EastFunction for the Option variant.
tagTagthe variant case (or tag) to test against

Returns

EastFunction<

BooleanType>


Importance

Importance(domain, range?): EastFunction<

StringType>

Convert a number

Expression to a magnitude string between ['negligible', 'moderate', 'large'].

Parameters

NameType
domainExpression<FloatType>
range[negligible: number, moderate: number]

Returns

EastFunction<

StringType>


IsEmpty

IsEmpty(collection): EastFunction<

BooleanType>

Return true if collection has zero elements, or false otherwise.

Parameters

NameType
collectionEastFunction<SetType | DictType>

Returns

EastFunction<

BooleanType>


IsFriday

IsFriday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Friday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsMonday

IsMonday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Monday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsNotNull

IsNotNull(value): EastFunction<

BooleanType>

Return true if value is null or false otherwise.

Parameters

NameType
valueEastFunction<EastType>

Returns

EastFunction<

BooleanType>


IsNull

IsNull(value): EastFunction<

BooleanType>

Return true if value is null or false otherwise.

Parameters

NameType
valueEastFunction<EastType>

Returns

EastFunction<

BooleanType>


IsSaturday

IsSaturday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Saturday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsSunday

IsSunday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Sunday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsThursday

IsThursday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Thursday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsTuesday

IsTuesday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Tuesday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsWednesday

IsWednesday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a Wednesday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsWeekday

IsWeekday(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a weekday.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


IsWeekend

IsWeekend(date): EastFunction<

BooleanType>

Return the a boolean function to determine if a datetime

Expression falls on a weekend.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

BooleanType>


MapOption

MapOption<T, F>(value, f): EastFunction<

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

Returns an EastFunction to map the data corresponding to the "some" case an Option variant through a function, while leaving the "none" case alone.

Type parameters

NameType
Textends EastType
Fextends (data: Variable<T>) => EastFunction

Parameters

NameTypeDescription
valueEastFunction<OptionType<T>>An EastFunction for the Option variant.
fFA function of data associated with the "some" case returning an EastFunction for the new associated data.

Returns

EastFunction<

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

See

None, Some, Unwrap, OptionType.


MatchTag

MatchTag<T, Tag, R, Fs>(value, tag, f, defaultValue): EastFunction<R>

Returns a EastType to based on provided tag of a

VariantType EastFunction.

Type parameters

NameType
Textends VariantType
Tagextends string | number | symbol
Rextends EastType
Fsextends (v: Variable<T["value"][Tag]>) => EastFunction<R>

Parameters

NameTypeDescription
valueEastFunction<T>An EastFunction for the Option variant.
tagTagthe variant case (or tag) to test against
fFsthe expression of the variant value
defaultValueEastFunction<R>the default value when the variant doesn't hag the tag

Returns

EastFunction<R>


Max

Max<T, U>(a, b): EastFunction<U>

Return the greater of a and b (note that null and NaN are greater than every other value).

Type parameters

NameType
Textends PrimitiveType
Uextends PrimitiveType

Parameters

NameType
aExpression<U>
bExpression<T>

Returns

EastFunction<U>


Min

Min<T, U>(a, b): EastFunction<U>

Return the lesser of a and b (note that null and NaN are greater than every other value).

Type parameters

NameType
Textends PrimitiveType
Uextends PrimitiveType

Parameters

NameType
aExpression<U>
bExpression<T>

Returns

EastFunction<U>


MonthNameShort

MonthNameShort(date): GetFunction<

StringType>

Return a

Print function to convert a datetime Expression to an abbreviated month name.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

GetFunction<

StringType>


MultiplyDict

MultiplyDict<X, Y>(first, second): EastFunction<

DictType<StringType, PromoteType<X, Y>>>

Multiply first by second where both are dictionaries.

Type parameters

NameType
Xextends IntegerType | FloatType
Yextends IntegerType | FloatType

Parameters

NameTypeDescription
firstExpression<DictType<StringType, X>>the first Expression to multiply
secondExpression<DictType<StringType, Y>>the second Expression to multiply

Returns

EastFunction<

DictType<StringType, PromoteType<X, Y>>>

Example

 // ...
// return the products revenue by multiplying the prices by the qtys
Amounts: MultiplyDict(
Variable('UnitPrices', DictType(StringType, FloatType)),
Variable('Quantities', DictType(StringType, FloatType))
),
// ...

OptionType

OptionType<T>(type):

VariantType<{ none: NullType = NullType; some: T = type }>

Return an EastType for the option variant with cases "none" (indicating the lack of data) and "some" (indicating the presence of data).

This is an alias for VariantType({ none: NullType, some: type }).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
typeTThe EastType associated with the "some" case.

Returns

VariantType<{ none: NullType = NullType; some: T = type }>

See

Some, Unwrap, MapOption, Option.


PadEnd

PadEnd(value, char, n): EastFunction<

StringType>

Pad the end of a string with a character up to a certain total length.

Parameters

NameType
valueEastFunction<StringType>
charstring | EastFunction<StringType>
nbigint | EastFunction<IntegerType>

Returns

EastFunction<

StringType>

Remarks

it is assumed that char has length 1.


PadStart

PadStart(value, char, n): EastFunction<

StringType>

Pad the start of a string with a character up to a certain total length.

Parameters

NameType
valueEastFunction<StringType>
charstring | EastFunction<StringType>
nbigint | EastFunction<IntegerType>

Returns

EastFunction<

StringType>

Remarks

it is assumed that char has length 1.


PrimaryKey

PrimaryKey(...values): EastFunction<

StringType>

Convenience function to convert one or more expressions into a string for a key.

Parameters

NameType
...valuesEastFunction<PrimitiveType>[]

Returns

EastFunction<

StringType>


PrintSeperated

PrintSeperated(x, thousands_seperator): EastFunction<

StringType>

Print a number with a seperator between the thousands, e.g. 1234 as "1,234"

Parameters

NameType
xExpression<IntegerType | FloatType>
thousands_seperatorstring

Returns

EastFunction<

StringType>


PrintTruncatedCurrency

PrintTruncatedCurrency(value): EastFunction<

StringType>

Return a comma seperated and rounded currency string from an integer.

Parameters

NameType
valueExpression<IntegerType>

Returns

EastFunction<

StringType>

PrintTruncatedCurrency(value): EastFunction<

StringType>

Return a comma seperated and rounded currency string from a number.

Parameters

NameType
valueExpression<FloatType>

Returns

EastFunction<

StringType>


RandomExponential

RandomExponential(): EastFunction<

FloatType>

Return a random number drawn from an exponential distribution.

Returns

EastFunction<

FloatType>


RandomKeys

RandomKeys<T>(collection, n): EastFunction<

SetType<T>>

Return a random subset of at most n keys from the input collection.

Type parameters

NameType
Textends StringType

Parameters

NameType
collectionEastFunction<DictType<T>>
nEastFunction<IntegerType>

Returns

EastFunction<

SetType<T>>


RandomValues

RandomValues<I>(collection, n): EastFunction<

DictType<StringType, I>>

Return a random subset of at most n values from the input collection (using sampling without replacement).

Type parameters

NameType
Iextends EastType

Parameters

NameType
collectionEastFunction<DictType<StringType, I>>
nEastFunction<IntegerType>

Returns

EastFunction<

DictType<StringType, I>>


RandomWeibull

RandomWeibull(shape): EastFunction<

FloatType>

Return a random number drawn from the Weibull distribution.

Parameters

NameType
shapeEastFunction<FloatType>

Returns

EastFunction<

FloatType>


Replace

Replace<T, U, V>(value, from, to): EastFunction<T>

Return value unless it equals from, in which case replace it with to.

Type parameters

NameType
Textends PrimitiveType
Uextends PrimitiveType
Vextends PrimitiveType

Parameters

NameType
valueEastFunction<T>
fromExpression<U>
toExpression<V>

Returns

EastFunction<T>


RoundMultiple

RoundMultiple<T>(value, divisor, rounding_mode?): EastFunction<T extends

NullType ? Nullable<T> : T>

Round number value up to nearest multiple of divisor.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
divisorEastFunction<T>
rounding_mode?RoundingMode

Returns

EastFunction<T extends

NullType ? Nullable<T> : T>


SetField

SetField<T, Name>(struct, name, value): EastFunction<T>

Update an existing field of a struct to a value of the same type.

Type parameters

NameType
Textends StructType
Nameextends string | number | symbol

Parameters

NameType
structEastFunction<T>
nameName
valueEastFunction<T["value"][Name]>

Returns

EastFunction<T>

See

Struct, Spread


Sigmoid

Sigmoid<T>(x): EastFunction<T>

Return a number EastFunction to peform ...

Type parameters

NameType
Textends FloatType

Parameters

NameType
xEastFunction<T>

Returns

EastFunction<T>


Some

Some<T>(data): VariantFunction<

VariantType<{ some: T }>>

Returns an EastFunction to construct the "some" case of the Option variant with associated data. This is an alias for Variant("some", value).

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
dataEastFunction<T>An EastFunction containing the associated data.

Returns

VariantFunction<

VariantType<{ some: T }>>

See

None, Unrwap, MapOption, OptionType, some.


Spread

Spread<T>(x): { [K in keyof T["value"]]: EastFunction<T["value"][K]> }

A helper function to assist in creating large structs. It works identically to how object spreading works in JavaScript. You can use it to either update existing fields in a struct, or to add new fields to a struct.

Type parameters

NameType
Textends StructType

Parameters

NameType
xEastFunction<T>

Returns

{ [K in keyof T["value"]]: EastFunction<T["value"][K]> }

See

Struct, SetField

Example

// build a struct with an additional field called new_field.
vars => Struct({ ...Spread(vars.large_struct), new_field: new_value })

ToEntries

ToEntries<T>(dict): EastFunction<

ArrayType<StructType<{ Key: StringType ; Value: T }>>>

Return a

ArrayType EastFunction to convert a dictionary into an array of key & value pairs

Type parameters

NameType
Textends EastType

Parameters

NameType
dictEastFunction<DictType<StringType, T>>

Returns

EastFunction<

ArrayType<StructType<{ Key: StringType ; Value: T }>>>


Truncate

Truncate<T>(value, type?): EastFunction<T>

Round number value towards zero to a whole number.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type?"float"

Returns

EastFunction<T>

Truncate<T>(value, type?): EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>

Round number value towards zero to the nearest integer.

Type parameters

NameType
Textends FloatType

Parameters

NameType
valueEastFunction<T>
type?"integer"

Returns

EastFunction<T extends

NullType ? Nullable<IntegerType> : IntegerType>


UnionAll

UnionAll<T>(collection): EastFunction<T>

Union all sets in collection into a single set

Expression.

Type parameters

NameType
Textends SetType

Parameters

NameType
collectionEastFunction<ArrayType<T> | DictType<StringType, T>>

Returns

EastFunction<T>


Unwrap

Unwrap<T, U>(value, defaultValue): EastFunction<T & U>

Returns an EastFunction to unwrap an Option variant, replacing the "none" case with defaultValue.

Type parameters

NameType
Textends EastType
Uextends EastType

Parameters

NameTypeDescription
valueEastFunction<OptionType<T>>An EastFunction for the Option variant.
defaultValueEastFunction<U>An EastFunction containing the associated data.

Returns

EastFunction<T & U>

See

None, Some, MapOption, OptionType.


WeekDescription

WeekDescription(cycle): EastFunction<

StringType>

Return a

Print function to convert a cycle Expression to an abbreviated week description.

Parameters

NameType
cycleEastFunction<IntegerType>

Returns

EastFunction<

StringType>


WeekOfMonth

WeekOfMonth(date): EastFunction<

IntegerType>

Return the number of whole weeks elapsed since the first Monday prior to or of the first day of the month.

Parameters

NameType
dateEastFunction<DateTimeType>

Returns

EastFunction<

IntegerType>