-
Notifications
You must be signed in to change notification settings - Fork 8
Standard Library
IO.write(Any)
Writes a value to the standard output.
IO.puts(Any)
Writes a value to the standard output in a newline.
Math.pi() -> Float
Returns the constant pi.
Math.ceil(Float) -> Integer
Rounds the number to the closest high integer.
Math.floor(Float) -> Integer
Rounds the number to the closest low integer.
Math.max(Float|Integer, Float|Integer) -> Float|Integer
Returns the biggest of the two numbers.
Math.min(Float|Integer, Float|Integer) -> Float|Integer
Returns the smallest of the two numbers.
Math.random(min Integer, max Integer) -> Integer
Generates a pseudorandom number between min
and max
.
Not a cryptographically pseudorandom number.
Type.of(Any) -> String
Returns the type as string of the value.
Type.toString(Any) -> String
Tries to convert the value to string.
Type.toInt(Any) -> Integer
Tries to convert the value to integer
Type.toFloat(Any) -> Float
Tries to convert the value to float.
Type.toArray(Any) -> Array
Tries to convert the value to a single element array.
String.count(String) -> Integer
Returns the number of UTF-8 codepoints in the string.
String.countBytes(String) -> Integer
Returns the number of bytes in the string.
When the string contains multibyte UTF-8 characters, it will report a larger number than String.count
String.lower(String) -> String
Converts all the characters of the string to lowercase.
String.upper(String) -> String
Converts all the characters of the string to uppercase.
String.capitalize(String) -> String
Capitalize the string to title case. All the first characters of words will be uppercase.
String.capitalize("hello world") // "Hello World"
String.trim(String, subset String) -> String
Removes all the characters from subset
from the start and end of the string.
String.trim("!@hello@!", "!@") // "hello"
String.trimLeft(String, subset String) -> String
Removes all the characters from subset
from the start of the string.
String.trimRight(String, subset String) -> String
Removes all the characters from subset
from the end of the string.
String.reverse(String) -> String
Reverses the characters of the string.
String.reverse("hello") // "olleh"
String.replace(String, search String, replace String) -> String
Replaces replace
with search
in the string.
String.replace("hello", "ll", "LL") // "heLLo"
String.slice(String, start Integer, length Integer) -> String
Returns a substring from start
with length
length.
String.slice("hello", 2, 3) // "llo"
String.join(Array, glue String) -> String
Joins an array with glue
into a string.
String.join(["hello", "world"], " beautiful ") // "hello beautiful world"
String.split(String, separator String) -> Array
Splits a string by separator
into an array.
String.split("hello world", " ") // ["hello", "world"]
String.first(String) -> String
Returns the first character of the string.
String.last(String) -> String
Returns the last character of the string.
String.contains?(String, search String) -> Boolean
Checks if the string contains search
.
String.contains?("hello", "ll") // true
String.starts?(String, prefix String) -> Boolean
Checks if the string starts with prefix
.
String.ends?(String, suffix String) -> Boolean
Checks if the string ends with suffix
.
String.match?(String, regex String) -> Boolean
Checks if the string matches a PCRE-compatible regular expression.
String.match?("123", "[a-z]+") // true
Enum.size(Array|String) -> Integer
Returns the number of elements in the enumerable.
Enum.empty?(Array|String) -> Boolean
Checks if the enumerable is empty.
Enum.contains?(Array|String, search Any) -> Boolean
Checks if the enumerable contains an element search
.
Enum.contains?(["hello", "world"], "hello") // true
Enum.reverse(Array|String) -> Array
Reverses the elements of the enumerable.
Enum.reverse([1, 2, 3]) // [3, 2, 1]
Enum.first(Array|String) -> Any
Returns the first element of the array.
Enum.last(Array|String) -> Any
Returns the last element of the array.
Enum.insert(Array, value Any) -> Array
Insert value
at the end of the array.
Enum.insert([1, 2], 3) // [1, 2, 3]
Enum.delete(Array, index Integer) -> Array
Delete an element at index index
.
Enum.random(Array|String) -> Any
Returns a random element from the array.
The function that calculates the random index is not cryptographically secure, if that matters.
Enum.random(1..100)
Enum.unique(Array|String) -> Array
Removes all duplicate values from the array.
Enum.unique([0, 1, 1, 2, 3]) // [0, 1, 2, 3]
Enum.map(Array|String, fn Function(element)) -> Array
Maps function fn
to every element of the array.
The element
parameter represents the array element in iteration.
Enum.map([1, 2, 3], fn x
x * x
end) // [1, 4, 9]
Enum.reduce(Array|String, start Any, fn Function(element, accumulator)) -> Any
Maps function fn
to every element of the array, accumulating the start
value.
element
is the array element in iteration and accumulator
the accumulated value.
Enum.reduce([1, 2, 3], 0, fn x, acc
x + acc
end) // 6
Enum.filter(Array|String, fn Function(element)) -> Array
Keeps every element of the array for which the function fn
returns true.
element
is the array element in iteration.
Enum.filter(1..10, fn x
x % 2 == 1
end) // [1, 3, 5, 7, 9]
Enum.find(Array|String, fn Function(element)) -> Any
Returns the first element for which the function fn
returns true.
This is a shortcut to running: Enum.first(Enum.filter(...))
element
is the array element in iteration.
Enum.find("abac", fn x
x == "b"
end) // "b"
Dict.size(Dictionary) -> Integer
Returns the number of elements in a dictionary.
Dict.contains?(Dictionary, key String) -> Boolean
Checks if the dictionary contains a key key
.
Dict.empty?(Dictionary) -> Boolean
Checks if the dictionary is empty.
Dict.insert(Dictionary, key String, value Any) -> Dictionary
Inserts a key key
with value value
into the dictionary.
Dict.insert(["name": "John", "age": 40], "married", false)
Dict.update(Dictionary, key String, value Any) -> Dictionary
Update a key key
with value value
on the dictionary.
Dict.update(["name": "John", "age": 40], "name", "Ben")
Dict.delete(Dictionary, key String) -> Dictionary
Deletes the key key
from the dictionary.
Dict.delete(["name": "John", "age": 40], "age")