Skip to content

Transformers

Transformers are projection-type functions that are bundled with Slice and translate types between each other.

Generic Transformers

There are built-in pure functions that operate on any contract type and map the values. They are the basic building blocks of data manipulation. They can be user-defined and are injected at build-time

Examples

  • add($value1, $value2)
  • find(#listValue, 'id', 4)
  • mult(avg(#listValue), $count)

Context Transformers

They translate Contexts between each other and are used inside Reducers to update internal data of the FSM when changing States. They are defined as a part of State Dictionary and can be injected at compile time.

Examples

  • #{stepIndex} <= nextStep(#stepIndex)
  • #{email, password, input_error} <= sanitize(#email), sanitize(#password), validate(#email, #password)}

Reducer Transformers

Function that translate from State+Action/Payload to State/Context can be injected into FSMs at compile time.

  • #{propertyA, propertyB} = reducerA(#propertyA, $payloadA, reducerB(#propertyB, $payloadB)

Model Transformers

Model transformers are a subtype of Effects that are context-free and are basically functions that mutates the Data Model.

  • #{counter} <= add(№counter, increaseGlobalCounter($value))

They can be composed with Predicates to create conditional mutations, but this approach is not recommended, since it splits the responsibility of Effects.

Built-Ins: Arithmetics

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
addNumber, [Number...]any numbersNumbersum of arguments
diffNumber, Numbertwo numbersNumberthe second number reduced by the first number
multNumber, [Number...]any numbersNumberproduct arguments
divNumber, Numbertwo numbersNumberthe first number divided by the second number
powNumber, Numberbase and powerNumberexponentiation of two numbers
incNumbera single numberNumbershortcut for add(number,1)
decNumbera single numberNumbershortcut for add(number,-1)
negNumbera single numberNumbershortcut for mult(number,-1)
invNumbera single numberNumbershortcut for div(1,number)
modNumber, Numbertwo numbersNumberfirst number modulo the second one
truncNumbera single numberNumbera nearest integer less than the argument
ceilNumbera single numberNumbera nearest integer greater than the argument
roundNumbera single numberNumbermathematically rounded argument

Built-Ins: Special Maths

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
sinNumbera single numberNumbersine of the argument
cosNumbera single numberNumbercosine of the argument
sqrtNumbera single numberNumbersquare root of the argument
logNumber, Numbernumber and baseNumberlogarithm of the number to the base
lnNumbernumberNumberlogarithm of the number to the e base
lgNumbernumberNumberlogarithm of the number to the 10 base
degNumbernumberNumberconverts degrees to radians
radNumbernumberNumberconverts radians to degs

Built-Ins: Statistics

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
maxNumber, [Number...]any numbersNumbermaximum of passed values
maxListlist of numbersNumbermaximum of passed list
minNumber, [Number...]any numbersNumberminimum of passed values
minListlist of numbersNumberminimum of passed list
avgNumber, [Number...]any numbersNumberaverage of passed values
avgListlist of numbersNumberaverage of passed list
medNumber, [Number...]any numbersNumbermedian of passed values
medListlist of numbersNumbermedian of passed list
sumListlist of numbersNumbersum of passed list
sumsqListlist of numbersNumbersum of passed list
sumProductList, [List...]Any amount of Lists, each being a list of numbersanysum of the products of corresponding values in two or more supplied arrays

Built-Ins: List Transformers

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
lenList- ListNumberquantity of items in the List
lookupList, any- List
- search element
anythe second argument, if it's present in the List, Null otherwise
filterByList, String, any- List of objects
- property name
- seek value
Listreturns new List with objects from the passed the List, which have the named property equal to passed seek value
findList, String, any- List of objects
- property name
- seek value
Listreturns new the first object from the passed the List, which have the named property equal to passed seek value, Null if none found
leftList, Number- List
- Length
Stringfirst N items in the List
rightList, Number- List
- Length
Stringlast N items in the List
indexOfList, any- List
- List
anythe index of search element, if it's present in the List, -1 otherwise

Built-Ins: String Transformers

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
substrString, Number [, Number]- String
- Start position
- End position
Stringa substring of given String, see JS String.Substring
lenString- ListMumberquantity of symbols in the string
leftString, Number- String
- Length
Stringfirst N symbols of the string
rightString, Number- String
- Length
Stringlast N symbols of the string
indexOfString, String- String
- search substring
anythe index of search substring, if it's present in the first string, -1 otherwise