Standard library
Every function Zyn has built in, generated from the list the type checker itself uses, so nothing is missing. They're written as Zyn signatures; a few things in them aren't syntax you write yourself:
fn Iterable<T>.map<T, R>(...)is a function called on a value:list.map { ... }.Iterablestands forList,MutableListandRange.vararg items: Ttakes any number of arguments.<N: Number>meansIntorFloat.<T: Comparable>means a type that can be compared with<:Int,Float,String,CharorBool.- Several signatures under one name are overloads: the one that fits the arguments is used.
Functions called on a value also work in a pipe and as plain calls: list.sorted(), list |> sorted and sorted(list) are the same.
#Functions
Called on their own: println(x), sqrt(2.0). Also the constant PI.
fn panic(message: String): NothingResult for those.fn assert(condition: Bool): Unitfn assert(condition: Bool, message: String): Unitcondition is false.fn assertEq<T>(actual: T, expected: T): Unitactual isn't equal to expected, and shows both.fn println(): Unitfn println(value: Any?): Unitfn mutableListOf<T>(vararg items: T): MutableList<T>mutableListOf<String>().fn mutableMapOf<K, V>(): MutableMap<K, V>mutableMapOf<String, Int>().#Lists and ranges
Iterable means any of List, MutableList and Range. Every one of these also works in a pipe (list |> filter { it > 2 }) and as a plain call (filter(list) { it > 2 }).
fn Iterable<T>.map<T, R>(transform: (T) -> R): List<R>transform's result for each item.fn Iterable<T>.mapIndexed<T, R>(transform: (Int, T) -> R): List<R>map, but transform also gets each item's index.fn Iterable<T>.flatMap<T, R>(transform: (T) -> List<R>): List<R>transform for each item and joins the lists it returns into one.fn Iterable<T>.filter<T>(predicate: (T) -> Bool): List<T>predicate is true.fn Iterable<T>.count<T>(): Intfn Iterable<T>.count<T>(predicate: (T) -> Bool): Intpredicate.fn Iterable<T>.any<T>(): Boolfn Iterable<T>.any<T>(predicate: (T) -> Bool): Boolpredicate.fn Iterable<T>.all<T>(predicate: (T) -> Bool): Boolpredicate (also when there are none).fn Iterable<T>.none<T>(): Boolfn Iterable<T>.none<T>(predicate: (T) -> Bool): Boolpredicate.fn Iterable<T>.find<T>(predicate: (T) -> Bool): T?predicate, or null.fn Iterable<T>.first<T>(): Tfn Iterable<T>.first<T>(predicate: (T) -> Bool): Tpredicate. Stops the program if there's none.fn Iterable<T>.last<T>(): Tfn Iterable<T>.last<T>(predicate: (T) -> Bool): Tpredicate. Stops the program if there's none.fn Iterable<T>.sumOf<T, N: Number>(selector: (T) -> N): Nselector's result for each item.fn Iterable<T>.min<T: Comparable>(): Tfn Iterable<T>.max<T: Comparable>(): Tfn Iterable<T>.minBy<T, C: Comparable>(selector: (T) -> C): Tselector gives the smallest value.fn Iterable<T>.maxBy<T, C: Comparable>(selector: (T) -> C): Tselector gives the largest value.fn Iterable<T>.minOrNull<T: Comparable>(): T?null if there are none.fn Iterable<T>.maxOrNull<T: Comparable>(): T?null if there are none.fn Iterable<T>.minByOrNull<T, C: Comparable>(selector: (T) -> C): T?minBy, or null if there are no items.fn Iterable<T>.maxByOrNull<T, C: Comparable>(selector: (T) -> C): T?maxBy, or null if there are no items.fn Iterable<T>.sortedDescending<T: Comparable>(): List<T>fn Iterable<T>.sortedBy<T, C: Comparable>(selector: (T) -> C): List<T>selector's result, smallest first.fn Iterable<T>.sortedByDescending<T, C: Comparable>(selector: (T) -> C): List<T>selector's result, largest first.fn Range.step(step: Int): Rangestep-th number of the range: (0..10).step(5) is 0, 5, 10.fn Iterable<T>.take<T>(count: Int): List<T>count items (or all, if there are fewer).fn Iterable<T>.chunked<T>(size: Int): List<List<T>>size (the last one may be shorter).fn Iterable<T>.distinct<T>(): List<T>fn Iterable<T>.joinToString<T>(): Stringfn Iterable<T>.joinToString<T>(separator: String): Stringfn Iterable<T>.joinToString<T>(separator: String, transform: (T) -> Any?): Stringseparator between them (", " if not given). transform turns each item into text.fn Iterable<T>.fold<T, R>(initial: R, operation: (R, T) -> R): Rinitial and combines it with each item in turn: [1, 2, 3].fold(0) { sum, x -> sum + x } is 6.fn Iterable<T>.reduce<T>(operation: (T, T) -> T): Tfold, starting with the first item. Stops the program if there are none.fn Iterable<T>.groupBy<T, K>(key: (T) -> K): Map<K, List<T>>key to the items that have it.fn Iterable<T>.toMutableList<T>(): MutableList<T>fn String.toMutableList(): MutableList<Char>#Mutable lists
Only for lists made with mutableListOf() or .toMutableList(). Items are also changed with list[i] = value.
fn MutableList<T>.addAll<T>(items: List<T>): Unititems at the end.fn MutableList<T>.insert<T>(index: Int, item: T): Unititem at index, moving the items after it along.fn MutableList<T>.removeAt<T>(index: Int): Tindex and returns it.fn MutableList<T>.remove<T>(item: T): Boolitem. True if there was one.#Maps
Look values up with map[key], which gives null for a missing key. Lambdas get the key and the value: map.filter { key, value -> value > 1 }.
fn Map<K, V>.contains<K, V>(key: K): Boolkey (the same as containsKey).fn Map<K, V>.getOrDefault<K, V>(key: K, default: V): Vkey, or default if there's none. map[key] ?? default does the same.fn Map<K, V>.toMutableMap<K, V>(): MutableMap<K, V>fn Map<K, V>.forEach<K, V>(action: (K, V) -> Unit): Unitaction with each key and value.fn Map<K, V>.map<K, V, R>(transform: (K, V) -> R): List<R>transform's result for each key and value.fn Map<K, V>.filter<K, V>(predicate: (K, V) -> Bool): Map<K, V>predicate is true.fn Map<K, V>.count<K, V>(): Intfn Map<K, V>.count<K, V>(predicate: (K, V) -> Bool): Intpredicate.fn Map<K, V>.all<K, V>(predicate: (K, V) -> Bool): Boolpredicate.#Mutable maps
Only for maps made with mutableMapOf() or .toMutableMap(). Set values with map[key] = value.
fn MutableMap<K, V>.remove<K, V>(key: K): V?key and returns its value, or null if it wasn't there.#Strings
Strings never change: these functions return new ones.
fn String.trim(): Stringfn String.contains(text: String): Boolfn String.contains(char: Char): Booltext (or char) is in the string.fn String.split(separator: String): List<String>separator.fn String.replace(old: String, new: String): Stringold replaced by new.fn String.repeat(times: Int): Stringtimes times over: "ab".repeat(3) is "ababab".fn String.substring(start: Int): Stringfn String.substring(start: Int, end: Int): Stringstart up to (not including) end, or to the end of the string.fn String.toIntOrNull(): Int?null if it isn't one.fn String.toFloatOrNull(): Float?null if it isn't one.fn String.toInt(): Result<Int, String>Result: Err with a message if it isn't one.fn String.toFloat(): Result<Float, String>Result: Err with a message if it isn't one.#Chars
#Numbers and conversions
Int is a 64-bit whole number, Float a 64-bit floating point number. They don't convert by themselves: use these.
#Result
Result<T, E> is Ok(value) or Err(error); it's written in Zyn, in the prelude every program gets. See Errors.
fn Result<T, E>.getOrElse<T, E>(default: T): TOk, or default for an Err.fn Result<T, E>.map<T, E, R>(transform: (T) -> R): Result<R, E>Ok; an Err stays as it is.fn Result<T, E>.mapErr<T, E, F>(transform: (E) -> F): Result<T, F>Err; an Ok stays as it is.fn Result<T, E>.andThen<T, E, R>(next: (T) -> Result<R, E>): Result<R, E>Ok.