Skip to content

Symbol

Type

The Symbol type is used to represent Number values with a unit, e.g. for money, weight, length, etc.

A symbol is defined by the keyword symbol followed by a text string which represents the symbol type.

symbol chf;

For a variable declaration, the type of an amount in chf is simply chf.

var moneyOwed = chf(2);

A chf literal is instantiated using chf(<number>).

The Symbol type can be thought of as amounts that have symbols associated with them. The actual type of e.g. chf(10) is Symbol<chf>.

Methods

divideBy

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Arguments

other - Number - number to divide this symbol amount with

Returns

Symbol<T> - a symbol of type T containg the value of dividing this with other

Usage
chf(20) / 2 == chf(10)

greaterThan

<function> Compare two amounts. Infix operator: >.

Receiver

Symbol<T>

Type Arguments

T

Arguments

other - Symbol<T>

Returns

Boolean - true if this is greater than other, otherwise false

greaterThanOrEqual

<function> Compare two amounts. Infix operator: >=.

Receiver

Symbol<T>

Type Arguments

T

Arguments

other - Symbol<T>

Returns

Boolean - true if this is greater than or equal to other, otherwise false

lessThan

<function> Compare two amounts. Infix operator: <.

Receiver

Symbol<T>

Type Arguments

T

Arguments

other - Symbol<T>

Returns

Boolean - true if this is less than other, otherwise false

lessThanOrEqual

<function> Compare two amounts. Infix operator: <=.

Receiver

Symbol<T>

Type Arguments

T

Arguments

other - Symbol<T>

Returns

Boolean - true if this is less than or equal to other, otherwise false

minus

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Arguments

other - Symbol<T> - symbol amount to subtract from this symbol amount

Returns

Symbol<T> - a symbol of type T containg the value of subtracting other from this

Usage
chf(10) - chf(5) == chf(5)

multiplyBy

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Arguments

other - Number - number to multiply with this symbol amount

Returns

Symbol<T> - a symbol of type T containg the value of multiplying this with other

Usage
chf(2) * 5 == chf(10)

negative

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Returns

Symbol<T> - the negation of this symbol

Usage
chf(-7).negative() == chf(7)

plus

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Arguments

other - Symbol<T> - symbol amount to add to this symbol amount

Returns

Symbol<T> - a symbol of type T containing the value of other added to this

Usage
chf(5) + chf(5) == chf(10)

remainder

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Arguments

other - Number - number to use as divisor for this symbol amount

Returns

Symbol<T> - a symbol of type T containg the remainder of the division of this with other

Usage
chf(7) % 5 == chf(2)

toNumber

<function> Drops the unit from this symbol, leaving only its numerical value.

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Returns

Number - the Number value of the Symbol

Usage
chf(10).toNumber() == 10

unit

<function>

Receiver

Symbol<T>

Type Arguments

T - user-defined symbol

Returns

Text - the unit of T as a Text representation

Usage
chf(10).unit() == "chf"

Inherited methods

toText

<function> Obtain the Text representation of this.

Receiver

T

Type Arguments

T

Returns

Text - the Text representation of this

Usage
chf(10).toText() == "10<chf>"

sum

<function> Returns the sum of all amounts in the collection. sum() applied to an empty list returns an amount of 0.

Receiver

Collection<Symbol<T>>

Type Arguments

T - the element type

Returns

Symbol<T> - the total of all amounts in the collection

Usage

listOf(chf(10), chf(10)).sum() == chf(20)
listOf<chf>().sum() == chf(0)