Std classes
We use the include keyword to load an external class. It could be static or non-static.
An example of including string std-lib:
include(static:std:string)Now you can perform standard operations on a string:
println(" Melon ".trim())
// "Melon"String
An example of all the standard methods offered for a String:
indexOfChar(letter: Char): IntindexOfFrom(substring: String, from: Int): Intsearches for a substring from the given positionindexOf(substring: String): Intcontains(substring: String): BoolstartsWith(prefix: String): BoolendsWith(suffix: String): Booluppercase(): Stringlowercase(): Stringpart(from: Int, to: Int)returns part of a stringsubstring(from: Int)trim(): Stringreplace(match: String, replacement: String): StringisAlpha(): Boolcheck if the string contains only English charactersisNumeric(): Boolif the string contains a valid numerical valuetoCharArray(): Array<Char>repeat(nTimes: Int): Stringrepeats the string n number of timessplit(delimiter: String): Array<String>splitOnce(delimiter: String): Array<String>splits the string once at a given delimitersize(): InttoIntRadix(radix: Int): Intparses string to a specific numeric basetoInt(): Intconverts the string into a valid base 10 int
Array
include(static:std:array)indexOf(element: Any): Intcontains(element: Int): BoolisEmpty(): BoolrecursiveLen(): Intreturns length of the array, include that of nested arraysflatten(): Arrayconverts a nested array into a flat onesize(): Intadd(element: Any): AnyremoveAt(index: Int): Anystring(): Stringa string representation of elements
Note that add() and removeAt() operations returns a newly allocated array.
Int
include(static:std:array)pow(power: Int): Introot(number: Int): Intmag(number: Int): Intreturns a positive integer
List
Unlike other classes, List is an Object type extension that needs to be instantiated.
include(std:list)
let names = new list(10) // creates a list of initial size 10
names.add("Hack")
names.add("Club!")
println(names)
// [Hack, Club!]add(element: Any)addAt(at: Int)get(at: Int): Anyset(element: Any, at: Int)indexOf(element: Any): Intcontains(element: Any): Boolremove(at: Int): Anyremoves and returns the element removedremoveElement(element: Any)removes the specific element from the listclear()clears all the elements presentarray(): ArrayarrayOfRange(from: Int, end: Int): Arraystring(): Stringreturns a string representation of elements present
Math
include(static:std:math)
println(math.max(5, 8))
// 8min(a: Int, b: Int): Intmax(a: Int, b: Int): Intabs(a: Int): Intavg(nums: Array<Int>): Intreturns average of the given int array
Type
include(static:std:etype)
println(typeOf("hello").isStdLib())
// true