Skip to content

Functions

Import use statements are necessary to bring these functions into scope, e.g.: use stdlib.v1.collection.take.

Collection

range

<function> Creates a new range as a list of numbers.

Arguments

start - Number - inclusive start of the range

end - Number - inclusive end of the range

step - Number - the increment step of each element in the range

Returns

List<Number> - a list containing all elements in the range

Usage
var x: List<Number> = range(start = -4, end = 4, step = 2); // listOf(-4, -2, 0, 2, 4)

Text

containsText

<function> Tests if the Text contains the segment.

Receiver

Text

Arguments

segment - Text - to look for within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

Boolean - true if the Text contains the segment, false otherwise

Usage
var x: Boolean = "abab".containsText("AB", false); // false
var y: Boolean = "abab".containsText("[AB]+", false); // false
var z: Boolean = "abab".containsText("AB", true); // true
var a: Boolean = "abab".containsText("[AB]+", true); // false

containsPattern

<function> Tests if the Text contains the regex pattern.

Receiver

Text

Arguments

regex - Text - pattern to check for (the regex format used corresponds to java.util.regex.Pattern)

Returns

Boolean - true if the Text contains the regex pattern, false otherwise

Usage
var x: Boolean = "abab".containsPattern("ab"); // true
var y: Boolean = "abab".containsPattern("[ab]+"); // true
var z: Boolean = "cdab".containsPattern("ab"); // true
var a: Boolean = "cdab".containsPattern("[ab]+"); // true

matchesPattern

<function> Tests if the Text matches the regex pattern.

Receiver

Text

Arguments

regex - Text - pattern to check for (the regex format used corresponds to java.util.regex.Pattern)

Returns

Boolean - true if the Text matches the regex pattern, false otherwise

Usage
var x: Boolean = "abab".matchesPattern("ab"); // false
var y: Boolean = "abab".matchesPattern("[ab]+"); // true
var z: Boolean = "cdab".matchesPattern("ab"); // false
var a: Boolean = "cdab".matchesPattern("[ab]+"); // false

endsWith

<function> Checks whether a Text ends with a suffix.

Receiver

Text

Arguments

suffix - Text - tests if the Text ends with this

ignoreCase - Boolean - toggle case sensitivity

Returns

Boolean - true if the Text ends with the suffix, false otherwise

Usage
var x: Boolean = "myTest".endsWith("St", ignoreCase = true); // true
var y: Boolean = "myTest".endsWith("St", ignoreCase = false); // false

startsWith

<function> Checks whether a Text starts with a prefix.

Receiver

Text

Arguments

prefix - Text - tests if the Text starts with this

ignoreCase - Boolean - toggle case sensitivity

Returns

Boolean - true if the Text starts with the prefix, false otherwise

Usage
var x: Boolean = "myTest".startsWith("mY", ignoreCase = true); // true
var y: Boolean = "myTest".startsWith("mY", ignoreCase = false); // false

equals

<function> Compares whether two Texts are equal.

Receiver

Text

Arguments

other - Text - the other Text to compare against

ignoreCase - Boolean - whether the comparison should be case sensitive

Returns

Boolean - true if both Text are equal, false otherwise

Usage
var x: Boolean = "one".equals("One", ignoreCase = true); // true
var y: Boolean = "one".equals("One", ignoreCase = false); // false

generateUUID

<function> Generates a UUID.

Returns

Text - a randomly generated UUID

Usage
var x: Text = generateUUID(); // "0a947f9a-ae02-4bb8-a105-3fad0ac0192b"

indexOf

<function> Checks for the index of the segment.

Receiver

Text

Arguments

segment - Text - to look for within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

Number - the first index of the segment if found, -1 otherwise

Usage
var x: Number = "myTest".indexOf("tesT", ignoreCase = true); // 2
var y: Number = "myTest".indexOf("Test", ignoreCase = false); // 2

indexOfAll

<function> Returns all indexes where the supplied segment starts.

Receiver

Text

Arguments

segment - Text - to look for within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

List<Number> - a list of indexes of the segment if found, empty list otherwise

Usage
var x: List<Number> = "-fa-fa-fa-fa".indexOfAll("-", ignoreCase = true); // [0, 3, 6, 9]
var y: List<Number> = "-fa-fa-fa-fa".indexOfAll("FA", ignoreCase = false); // [1, 4, 7, 10]

lastIndexOf

<function> Checks for the last index of the segment.

Receiver

Text

Arguments

segment - Text - to look for within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

Number - the last index of the segment if found, -1 otherwise

Usage
var x: Number = "-fa-fa-fa-fa".lastIndexOf("-", ignoreCase = true); // 9
var y: Number = "-fa-fa-fa-fa".lastIndexOf("FA", ignoreCase = false); // 10

isEmpty

<function> Checks if a Text is empty (contains no characters).

Receiver

Text

Returns

Boolean - true if the Text is empty (contains no characters), false otherwise

Usage
var x: Boolean = "".isEmpty(); // true
var y: Boolean = " ".isEmpty(); // false
var z: Boolean = "a".isEmpty(); // false

removePrefix

<function> Removes the given prefix Text from the beginning of the receiver Text.

Receiver

Text

Arguments

prefix - Text - to remove from the start of the Text

Returns

Text - Text with prefix removed if found, original Text otherwise

Usage
var x: Text = "abc".removePrefix("ab"); // "c"
var y: Text = "abc".removePrefix("bc"); // "abc"

removeSuffix

<function> Removes the supplied suffix from the end of a Text.

Receiver

Text

Arguments

suffix - Text - to remove from the end of the Text

Returns

Text - Text with suffix removed if found, original Text otherwise

Usage
var x: Text = "abc".removeSuffix("c"); // "ab"
var y: Text = "abc".removeSuffix("b"); // "abc"

repeat

<function> Repeats a given Text pattern a given number of times.

Receiver

Text

Arguments

times - Number - to repeat the Text

Returns

Text - a Text representing the receiver Text repeated a given number of times

Usage
var x: Text = "abc".repeat(3); // "abcabcabc"

replaceFirst

<function> Replaces the first occurrence of old, if it exists, with new in the Text.

Receiver

Text

Arguments

old - Text - to look for within the Text

new - Text - to replace old within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

Text - the Text with the first occurrence of old, if it exists, replaced by new, original Text otherwise

Usage
var x: Text = "aAb".replaceFirst("a", "b", ignoreCase = true); // "bAb"
var y: Text = "aAb".replaceFirst("a", "b", ignoreCase = false); // "bab"
var z: Text = "abab".replaceFirst("ab", "cd", ignoreCase = false); // "cdab"

replaceAll

<function> Replaces all occurrences of old, if it exists, with new in the Text.

Receiver

Text

Arguments

old - Text - to look for within the Text

new - Text - to replace old within the Text

ignoreCase - Boolean - toggle case sensitivity

Returns

Text - the Text with all occurrences of old, if it exists, replaced by new, original Text otherwise

Usage
var x: Text = "aAb".replaceAll("a", "b", ignoreCase = true); // "bbb"
var y: Text = "aAb".replaceAll("a", "b", ignoreCase = false); // "bAb"
var z: Text = "abab".replaceAll("ab", "cd", ignoreCase = false); // "cdcd"

slice

<function> Slices a Text from a starting index to an inclusive end index.

Receiver

Text

Arguments

indexStart - Number - the inclusive start position in the Text from which to start slicing

indexEnd - Number - the exclusive end position in the Text from which to end slicing

Returns

Text - a sliced portion of the original Text

Usage
var x: Text = "one".slice(0, 2); // "on"

split

<function> Splits a Text based on the supplied delimiter.

Receiver

Text

Arguments

delimiter - Text - on which to divide up the Text

Returns

List<Text> - a list of substrings split by the delimiter, original Text as a single item list otherwise

Usage
var x: List<Text> = "a-+b-+c-d".split("-+"); // ["a", "b", "c-d"]

toLowercase

<function> Converts Text to lowercase.

Receiver

Text

Returns

Text - the Text with all alphabetic characters in lowercase

Usage
var x: Text = "aBcD".toLowercase(); // "abcd"

toUppercase

<function> Converts Text to uppercase.

Receiver

Text

Returns

Text - the Text with all alphabetic characters in uppercase

Usage
var x: Text = "aBcD".toUppercase(); // "ABCD"

trim

<function> Trims whitespace at both the start and end of the given Text.

Receiver

Text

Returns

Text - the trimmed text

Usage
var x: Text = " one ".trim(); // "one"

trimLeft

<function> Trims whitespace at the start of the given Text.

Receiver

Text

Returns

Text - the left-trimmed text

Usage
var x: Text = " a ".trimLeft(); // "a "
var y: Text = " \t a ".trimLeft(); // "a "

trimRight

<function> Trims whitespace at the end of the given Text.

Receiver

Text

Returns

Text - the right-trimmed text

Usage
var x: Text = " a ".trimRight(); // " a"
var y: Text = " a \t ".trimRight(); // " a"

Math

product

<function> Multiplies every element of the Collection together. One (1) is always returned for the product of an empty Collection. A Collection containing a zero (0) value will always return 0.

Receiver

Collection<Number>

Returns

Number - the result of multiplying each element of the Collection with each other

Usage
var x: Number = listOf(1, 2, 3).product(); // 6
var y: Number = setOf(1, 2, 3).product(); // 6

toThePowerOf

<function> Raises a Number to the given exponent using double-precision arithmetic (IEEE 754 standard), which may affect the precision of the result.

Receiver

Number

Arguments

exponent - Number - the exponent to raise the Number

Returns

Optional<Number> - An Optional of type Some of the Number raised to the exponent if successful, otherwise an Optional of type None

Usage
var x: Optional<Number> = 2.toThePowerOf(4); // 16

log

<function> Returns the logarithm with the given base using double-precision arithmetic (IEEE 754 standard), which may affect the precision of the result.

Receiver

Number

Arguments

base - Number - the base of the logarithm

Returns

Optional<Number> - An Optional of type Some of the Number raised to the exponent if successful, otherwise an Optional of type None

Usage
var x: Optional<Number> = 10.log(10); // 1

minBetween

<function> Returns the minimum between two (2) Number.

Arguments

a - Number - the first Number

b - Number - the second Number

Returns

Number - the minimum between Number a and Number b

Usage
var x: Number = minBetween(1, 2); // 1

maxBetween

<function> Returns the maximum between two (2) Number.

Arguments

a - Number - the first Number

b - Number - the second Number

Returns

Number - the maximum between Number a and Number b

Usage
var x: Number = maxBetween(1, 2); // 2

min

<function> Returns the minimum of a Collection of Numbers.

Receiver

Collection<Number>

Returns

Optional<Number> - An Optional of type Some of the minimum, otherwise an Optional of type None if the Collection is empty.

Usage
var x: Optional<Number> = listOf(1, 2, 3).min(); // Some(1)
var y: Optional<Number> = setOf(1, 2, 3).min(); // Some(1)

max

<function> Returns the maximum of a Collection of Numbers.

Receiver

Collection<Number>

Returns

Optional<Number> - An Optional of type Some of the maximum, otherwise an Optional of type None if the Collection is empty.

Usage
var x: Optional<Number> = listOf(1, 2, 3).max(); // Some(3)
var y: Optional<Number> = setOf(1, 2, 3).max(); // Some(3)