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
Type parameters
Name | Type |
---|---|
T | extends 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
Abs
▸ Abs(x
): EastFunction
<
IntegerType
>
Return the absolute value of a number or integer
Expression.Parameters
Name | Type |
---|---|
x | Expression <IntegerType > |
Returns
EastFunction
<
IntegerType
>
AddAll
▸ AddAll(collection
): EastFunction
<
FloatType
>
Add all collection values into a single float or integer
Expression.Parameters
Name | Type |
---|---|
collection | EastFunction <ArrayType <FloatType >> |
Returns
EastFunction
<
FloatType
>
AddDict
▸ AddDict<T
>(d1
, d2
): MapValuesFunction
<
DictType
<StringType
, any
>>
Add first
to second
where both are dictionaries.
Type parameters
Name | Type |
---|---|
T | extends NumericType |
Parameters
Name | Type |
---|---|
d1 | EastFunction <DictType <StringType , T >> |
d2 | EastFunction <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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type |
---|---|
value | EastFunction <T > |
unit | TimeUnit | CalendarUnit |
Returns
EastFunction
<T
>
▸ Ceiling<T
>(value
, type?
): EastFunction
<T
>
Round number value
up to a whole number.
Type parameters
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type |
---|---|
a | Expression <T > |
b | Expression <T > |
Returns
EastFunction
<
IntegerType
>
ConvertFloatDict
▸ ConvertFloatDict(dict
): EastFunction
<
DictType
<StringType
, IntegerType
>>
Convert a float
DictType to an integer DictType.Parameters
Name | Type |
---|---|
dict | EastFunction <DictType <StringType , FloatType >> |
Returns
EastFunction
<
DictType
<StringType
, IntegerType
>>
ConvertIntegerDict
▸ ConvertIntegerDict(dict
): EastFunction
<
DictType
<StringType
, FloatType
>>
Convert an integer
DictType to an float DictType.Parameters
Name | Type |
---|---|
dict | EastFunction <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
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
day_name | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
T | extends VariantType |
Tag | extends string | number | symbol |
K | extends StringType |
Parameters
Name | Type | Description |
---|---|---|
collection | EastFunction <DictType <K , T >> | an Expression for a collection of variants |
tag | Tag | the 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
Name | Type |
---|---|
T | extends DateTimeType |
Parameters
Name | Type |
---|---|
value | EastFunction <T > |
unit | TimeUnit | CalendarUnit |
Returns
EastFunction
<T
>
▸ Floor<T
>(value
, type
): EastFunction
<T
extends
NullType
? Nullable
<IntegerType
> : IntegerType
>
Round number value
down to nearest integer
Type parameters
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
Variants | extends Record <string , EastType > |
Fs | extends { [K in string | number | symbol]: Function } |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends VariantType |
Tag | extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | An EastFunction for the Option variant. |
tag | Tag | the 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
Name | Type |
---|---|
domain | Expression <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
Name | Type |
---|---|
collection | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <DateTimeType > |
Returns
EastFunction
<
BooleanType
>
IsNotNull
▸ IsNotNull(value
): EastFunction
<
BooleanType
>
Return true if value
is null
or false
otherwise.
Parameters
Name | Type |
---|---|
value | EastFunction <EastType > |
Returns
EastFunction
<
BooleanType
>
IsNull
▸ IsNull(value
): EastFunction
<
BooleanType
>
Return true if value
is null
or false
otherwise.
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
F | extends (data : Variable <T >) => EastFunction |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <OptionType <T >> | An EastFunction for the Option variant. |
f | F | A function of data associated with the "some" case returning an EastFunction for the new associated data. |
Returns
EastFunction
<
OptionType
<ReturnType
<F
>["type"
]>>
See
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
Name | Type |
---|---|
T | extends VariantType |
Tag | extends string | number | symbol |
R | extends EastType |
Fs | extends (v : Variable <T ["value" ][Tag ]>) => EastFunction <R > |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <T > | An EastFunction for the Option variant. |
tag | Tag | the variant case (or tag) to test against |
f | Fs | the expression of the variant value |
defaultValue | EastFunction <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
Name | Type |
---|---|
T | extends PrimitiveType |
U | extends PrimitiveType |
Parameters
Name | Type |
---|---|
a | Expression <U > |
b | Expression <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
Name | Type |
---|---|
T | extends PrimitiveType |
U | extends PrimitiveType |
Parameters
Name | Type |
---|---|
a | Expression <U > |
b | Expression <T > |
Returns
EastFunction
<U
>
MonthNameShort
▸ MonthNameShort(date
): GetFunction
<
StringType
>
Return a
Print function to convert a datetime Expression to an abbreviated month name.Parameters
Name | Type |
---|---|
date | EastFunction <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
Name | Type |
---|---|
X | extends IntegerType | FloatType |
Y | extends IntegerType | FloatType |
Parameters
Name | Type | Description |
---|---|---|
first | Expression <DictType <StringType , X >> | the first Expression to multiply |
second | Expression <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
type | T | The EastType associated with the "some" case. |
Returns
VariantType
<{ none
: NullType
= NullType; some
: T
= type }>
See
PadEnd
▸ PadEnd(value
, char
, n
): EastFunction
<
StringType
>
Pad the end of a string with a character up to a certain total length.
Parameters
Name | Type |
---|---|
value | EastFunction <StringType > |
char | string | EastFunction <StringType > |
n | bigint | 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
Name | Type |
---|---|
value | EastFunction <StringType > |
char | string | EastFunction <StringType > |
n | bigint | 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
Name | Type |
---|---|
...values | EastFunction <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
Name | Type |
---|---|
x | Expression <IntegerType | FloatType > |
thousands_seperator | string |
Returns
EastFunction
<
StringType
>
PrintTruncatedCurrency
▸ PrintTruncatedCurrency(value
): EastFunction
<
StringType
>
Return a comma seperated and rounded currency string from an integer.
Parameters
Name | Type |
---|---|
value | Expression <IntegerType > |
Returns
EastFunction
<
StringType
>
▸ PrintTruncatedCurrency(value
): EastFunction
<
StringType
>
Return a comma seperated and rounded currency string from a number.
Parameters
Name | Type |
---|---|
value | Expression <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
Name | Type |
---|---|
T | extends StringType |
Parameters
Name | Type |
---|---|
collection | EastFunction <DictType <T >> |
n | EastFunction <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
Name | Type |
---|---|
I | extends EastType |
Parameters
Name | Type |
---|---|
collection | EastFunction <DictType <StringType , I >> |
n | EastFunction <IntegerType > |
Returns
EastFunction
<
DictType
<StringType
, I
>>
RandomWeibull
▸ RandomWeibull(shape
): EastFunction
<
FloatType
>
Return a random number drawn from the Weibull distribution.
Parameters
Name | Type |
---|---|
shape | EastFunction <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
Name | Type |
---|---|
T | extends PrimitiveType |
U | extends PrimitiveType |
V | extends PrimitiveType |
Parameters
Name | Type |
---|---|
value | EastFunction <T > |
from | Expression <U > |
to | Expression <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <T > |
divisor | EastFunction <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
Name | Type |
---|---|
T | extends StructType |
Name | extends string | number | symbol |
Parameters
Name | Type |
---|---|
struct | EastFunction <T > |
name | Name |
value | EastFunction <T ["value" ][Name ]> |
Returns
EastFunction
<T
>
See
Sigmoid
▸ Sigmoid<T
>(x
): EastFunction
<T
>
Return a number EastFunction to peform ...
Type parameters
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
x | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
data | EastFunction <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
Name | Type |
---|---|
T | extends StructType |
Parameters
Name | Type |
---|---|
x | EastFunction <T > |
Returns
{ [K in keyof T["value"]]: EastFunction<T["value"][K]> }
See
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 pairsType parameters
Name | Type |
---|---|
T | extends EastType |
Parameters
Name | Type |
---|---|
dict | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Name | Type |
---|---|
T | extends FloatType |
Parameters
Name | Type |
---|---|
value | EastFunction <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
Type parameters
Name | Type |
---|---|
T | extends SetType |
Parameters
Name | Type |
---|---|
collection | EastFunction <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
Name | Type |
---|---|
T | extends EastType |
U | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
value | EastFunction <OptionType <T >> | An EastFunction for the Option variant. |
defaultValue | EastFunction <U > | An EastFunction containing the associated data. |
Returns
EastFunction
<T
& U
>
See
WeekDescription
▸ WeekDescription(cycle
): EastFunction
<
StringType
>
Return a
Print function to convert a cycle Expression to an abbreviated week description.Parameters
Name | Type |
---|---|
cycle | EastFunction <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
Name | Type |
---|---|
date | EastFunction <DateTimeType > |
Returns
EastFunction
<
IntegerType
>