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
roundNumber, [Number]- Number- Precision = 0Numbermathematically rounded Number to Precision digits. Precision must be a non-negative integer

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, Number- Number
- Base
Numberlogarithm 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...]Numeric lists of the same lengthNumbersum of the products of corresponding values in two or more supplied lists

Built-Ins: List Transformers

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
lenList- ListNumberquantity of items in the List
lookupList, any- List
- search element
anythe search element, if it's present in the List, Null otherwise
leftList, Number- List
- Length
Stringfirst Length items in the List
rightList, Number- List
- Length
Stringlast Length items in the List
firstList- List
anyfirst element in the List
lastList- List
>
anylast element in the List
indexOfList, any- List
- Value
anyzero-based index of Value, if it's present in the List, -1 otherwise
concatList, [List...]- Lists
Listjoins all passed Lists consequently and returns a new List
sampleList, Number- List
- item count
Listreturns new List, containing N random items from List, without dublicates. N is item count, if item count >= 1. If item count is a fraction, N is the percentage of total quantity, rounded down
everyList, Number, [Number]- List
- N
- offset = 0
Listreturns new List, containing every Nth item items from List, starting with offset
shuffleList- List
Lista new List that contains the same items as the original List but in randomized order
repeatNumber, any- Quantity
- Value sample
List (or Collection)new List, containing Quantity replicated instances of Value sample
pickList, List- Source List
- Keys
Listreturns new List containing values from Source List with indeces in Keys, in order of appearance in original List
pickList, Number- Source List
- Index
anyreturns a value from Source List at position Index
reverseList- Source List
Listreturns a new List comprised of Source List elements in reverse order
sortList- Source ListListreturns a new List comprised of Source List elements in ascending order

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- StringMumberquantity of symbols in the String
leftString, Number- String
- Length
Stringfirst Length symbols of the String
rightString, Number- String
- Length
Stringlast Length symbols of the String
indexOfString, String- String
- Search substring
anythe index of Search substring, if it's present in the String, -1 otherwise
concatString, [String...]- Strings
Stringjoins all passed Strings consequently and returns a new String
sampleString, Number- String
- characters count
Stringreturns new String, containing N random symbols from String, while every symbol position of input String is used at most once. N is character count, if character count >= 1. If character count is a fraction, N is the percentage of total quantity, rounded down
shuffleString- String
Stringa new String that contains the same items as the original String but in randomized order
padLeftString, Number, String-String
- target length
- pattern
Stringprepends String with pattern repeatedly to approach target length as close as possible, without exceeding it. If original String is longer than target length, returns it immediately
padRightString, Number, String-String
- target length
- pattern
Stringappends pattern to String repeatedly to approach target length as close as possible, without exceeding it. If original String is longer than target length, returns it immediately
reverseString- Source String
Stringreturns a new String comprised of Source String characters in reverse order

Built-Ins: Object Transformers

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
keysObject- Object
Lista List containing all defined keys of Object in enumeration order
valuesObject- Object
Lista List containing all defined values of Object in enumeration order
zipList, List- Keys list
- Value list
Objectnew Object which keys are created from the Key list and values - from the Value list. Both Lists should be of equal length and contain only String and/or Number values (or none)
setAttrObject, String, any- Object
- Key string
- Value
Objecta clone of Object, but with its Key string property set to Value
unsetAttrObject, String- Object
- Key string
Objecta clone of Object, but with its Key string property removed
mergeObject, [Object...]- Destination
- Source objects
Objectnew Object that clones Destination with all keys from all Source objectы and their respective values copied. When multiple Source Objects are passed, eponymous properties are overwritten from right to left, i.e. the latest Source Object with given property name takes priority
intersectObject, [Object...]- Source ObjectsObjectnew Object that contains only properties that exist in all provided Source Objects. Eponymous properties are overwritten from right to left, i.e. the latest Source Object with given property name takes priority
pickObject, List- Source Object
- Keys
Objectreturns new Object containing values from Source List with keys listed in Keys, in order of appearance in original Object
pickObject, String- Source Object
- Key
anyreturns a single value from Source Object with key Key

Built-Ins: Collection Transformers

NOTE

These functions are meant to work with Collections. Hereby Collection type name is explicitely used as type to distinguish from any other List, while in the built code those would be the same interface.

Function(s)Argument TypeArgument ValueReturn TypeReturn Value
filterByCollection, String, any- Collection
- property name
- seek value
Collectionreturns new Collection that includes only those items from input Collection , which have the property name attribute equal to seek value
omitCollection, String, any- Collection
- property name
- seek value
Collectionreturns new Collection which excludes items from input Collection with property name attribute equal to seek value
findCollection, String, any- Collection
- property name
- seek value
Objectreturns new the first item from the Collection, which have the property name attribute equal to seek value. Null is returned if none is found
pluckCollection, String- Collection
- property name
Listreturns new List, that is comprised of all property name attribute values of items in the Collection, in the order of appearance
sortCollection, [String], [any]- Collection
- Key Name = id
- Default Value = Null
Collectionreturns a new Collection comprised of Collection elements, sorted ascendingly by Key Name field. If the field is absent, it fallbacks to Default Value