prelude#
Names available in every module; no import required.
Bool Type#
Boolean truth values true and false; conditions require this type.
type Bool { ... }Bool.clone#
Returns the value itself: a Bool copies by value.
fn clone() BoolClonable Interface#
A type whose values can be duplicated. Plain data is Clonable; resource handles,
natives without a clone of their own (a Regex, a Pipe), function values, and
any record, alternative or collection holding one of those are not. There is nothing
to implement: the bound T Clonable makes value.clone() available on a type
parameter.
interface Clonable {
fn clone() Self
}Clonable.clone#
Returns an independent deep copy of this value.
fn clone() SelfComparable Interface#
A type with a total order; compare agrees with equals when both are implemented.
interface Comparable {
fn compare(other Self) Int
}Comparable.compare#
Orders this value against another of the same type: negative when it sorts before, zero when neither sorts first, positive when it sorts after.
fn compare(other Self) IntEqual Interface#
A type that can be compared for equality. Built-in data keeps its value semantics; an explicit implementation chooses what counts as the same value.
interface Equal {
fn equals(other Self) Bool
}Equal.equals#
Compares this value with another value of the same type.
fn equals(other Self) BoolError Type#
An expected failure as a plain value: a message, a short code callers can branch on,
and string details. Build one like any record:
Error("no such file", kind: "ENOENT", details: {"path": path}). T! is
Result[T, Error].
type Error {
message String
kind String? = null
details Map[String, String] = Map[String, String]()
}Error.details#
Extra facts about the failure, such as the path or operation, keyed by name.
details Map[String, String] = Map[String, String]()Error.kind#
A short code for what went wrong, or null when no code fits. The kind itself
never allocates when it is a literal or at most 15 bytes. The standard library
reports POSIX errno names (EAUTH is Manuscript’s own), so
error.kind == "ENOENT" means the same on every platform:
EINVAL: caller input is invalidEBADMSG: input data is malformedEOVERFLOW: a limit was exceededERANGE: a value or index is out of rangeENOENT: not foundEEXIST: already existsENOTEMPTY: directory not emptyEACCES: permission deniedENOTSUP: unsupportedENOTTY: not a terminalEBADF: resource closedEIO: a task, process or peer ended abnormallyEAGAIN: service unavailableEBUSY: resource busyENAMETOOLONG: a file name or path is too longELOOP: too many symbolic linksENOSPC: no space left on the deviceEROFS: the file system is read-onlyEXDEV: the paths are on different devicesEMFILE: too many open filesETIMEDOUT: a deadline expiredECANCELED: cancelledEAUTH: authentication failed
Your own code uses its own prefix, such as "EQUOTA".
kind String? = nullError.message#
Human-readable description of the failure.
message StringFloat Type#
Binary floating-point values, including signed zero, infinities and NaN.
type Float { ... }Float.abs#
Returns the absolute value; NaN stays NaN and -0.0 becomes 0.0.
fn abs() FloatFloat.clone#
Returns the value itself: a Float copies by value.
fn clone() FloatFloat.compare#
Returns -1, 0 or 1 in a total order: -0.0 equals 0.0, and NaN is equal to NaN and greater than every other value, including +Inf.
fn compare(other Float) IntFloat.is_finite#
Tests whether the value is neither NaN nor an infinity.
fn is_finite() BoolFloat.is_nan#
Tests whether the value is NaN.
fn is_nan() BoolFloat.sign#
Returns -1.0 or 1.0 by sign; zeros and NaN are returned unchanged.
fn sign() FloatFloat.to_exponential#
Formats in scientific notation with digits fractional digits, from 0 to 100; a
count outside 0..100 faults.
fn to_exponential(digits Int) StringFloat.to_fixed#
Formats with digits fractional digits, from 0 to 100; a magnitude of 1e21 or
more uses the ordinary round-trip notation. A count outside 0..100 faults.
Rounding is binary64 round half to even.
Example: 3.14159.to_fixed(2) is "3.14".
fn to_fixed(digits Int) StringFloat.to_float32#
Converts to Float32, rounding to the nearest binary32 value. A finite value too large for Float32 returns null instead of becoming infinity; NaN and infinities convert unchanged.
fn to_float32() Float32?Float.to_precision#
Formats with precision significant digits, from 1 to 100, keeping trailing
zeros; a count outside 1..100 faults.
fn to_precision(precision Int) StringFloat.to_string#
Returns the shortest round-trip representation, including NaN and signed infinities.
fn to_string() StringFloat.truncate_to_int#
Truncates toward zero, or returns null for nonfinite values or Int overflow.
fn truncate_to_int() Int?Float32 Type#
Binary32 floating-point values; each operation rounds to binary32, and literals need a Float32 type to adopt it.
type Float32 { ... }Float32.abs#
Returns the absolute value; NaN stays NaN and -0.0 becomes 0.0.
fn abs() Float32Float32.clone#
Returns the value itself: a Float32 copies by value.
fn clone() Float32Float32.compare#
Returns -1, 0 or 1 in a total order: -0.0 equals 0.0, and NaN is equal to NaN and greater than every other value, including +Inf.
fn compare(other Float32) IntFloat32.is_finite#
Tests whether the value is neither NaN nor an infinity.
fn is_finite() BoolFloat32.is_nan#
Tests whether the value is NaN.
fn is_nan() BoolFloat32.sign#
Returns -1.0 or 1.0 by sign; zeros and NaN are returned unchanged.
fn sign() Float32Float32.to_float#
Converts to Float; every Float32 converts exactly.
fn to_float() FloatFloat32.to_float64#
Converts to Float64; every Float32 converts exactly.
fn to_float64() Float64Float32.truncate_to_int#
Truncates toward zero, or returns null for nonfinite values or Int overflow.
fn truncate_to_int() Int?Float64 Type#
Binary64 floating-point values; the same type as Float.
type Float64 { ... }Hashable Interface#
A type with a stable hash that is consistent with its Equal implementation.
interface Hashable {
fn hash() Int
}Hashable.hash#
Returns a stable hash consistent with equals for the same value.
fn hash() IntInt Type#
Signed whole numbers with checked arithmetic; overflow and division by zero fault.
type Int { ... }Int.abs#
Returns the absolute value; the most negative value has none and faults like any overflow.
fn abs() IntInt.clone#
Plain numbers and flags copy by value: their clone is the value itself.
fn clone() IntInt.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other Int) IntInt.milliseconds#
Returns a Duration of this many milliseconds; a count that overflows nanoseconds faults.
fn milliseconds() DurationInt.minutes#
Returns a Duration of this many minutes; a count that overflows nanoseconds faults.
fn minutes() DurationInt.seconds#
Returns a Duration of this many seconds; a count that overflows nanoseconds faults.
fn seconds() DurationInt.sign#
Returns -1, 0 or 1 as this value is negative, zero or positive.
fn sign() IntInt.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringInt.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalInt.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatInt.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32Int.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringInt.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntInt.to_int16#
Converts to Int16, or returns null when the value is outside Int16’s range.
fn to_int16() Int16?Int.to_int32#
Converts to Int32, or returns null when the value is outside Int32’s range.
fn to_int32() Int32?Int.to_int64#
Returns the same value. Int64 is another name for Int while Int is 64 bits
wide.
fn to_int64() Int64Int.to_int8#
Converts to Int8, or returns null when the value is outside Int8’s range.
fn to_int8() Int8?Int.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?Int.to_uint16#
Converts to UInt16, or returns null when the value is outside UInt16’s range.
fn to_uint16() UInt16?Int.to_uint32#
Converts to UInt32, or returns null when the value is outside UInt32’s range.
fn to_uint32() UInt32?Int.to_uint64#
Converts to UInt64, or returns null when the value is negative.
fn to_uint64() UInt64?Int.to_uint8#
Converts to UInt8, or returns null when the value is outside UInt8’s range.
fn to_uint8() UInt8?Int16 Type#
Signed 16-bit whole numbers (-32768 to 32767); arithmetic faults when the result leaves the range.
type Int16 { ... }Int16.abs#
Returns the absolute value; the most negative value has none and faults like any overflow.
fn abs() Int16Int16.clone#
Returns the value itself: a Int16 copies by value.
fn clone() Int16Int16.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other Int16) IntInt16.sign#
Returns -1, 0 or 1 as this value is negative, zero or positive.
fn sign() IntInt16.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringInt16.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalInt16.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatInt16.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32Int16.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringInt16.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntInt16.to_int64#
Converts to Int64; every value fits, so no check is needed.
fn to_int64() Int64Int16.to_int8#
Converts to Int8, or returns null when the value is outside Int8’s range.
fn to_int8() Int8?Int16.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?Int32 Type#
Signed 32-bit whole numbers (-2147483648 to 2147483647); arithmetic faults when the result leaves the range.
type Int32 { ... }Int32.abs#
Returns the absolute value; the most negative value has none and faults like any overflow.
fn abs() Int32Int32.clone#
Returns the value itself: a Int32 copies by value.
fn clone() Int32Int32.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other Int32) IntInt32.sign#
Returns -1, 0 or 1 as this value is negative, zero or positive.
fn sign() IntInt32.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringInt32.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalInt32.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatInt32.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32Int32.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringInt32.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntInt32.to_int16#
Converts to Int16, or returns null when the value is outside Int16’s range.
fn to_int16() Int16?Int32.to_int64#
Converts to Int64; every value fits, so no check is needed.
fn to_int64() Int64Int32.to_int8#
Converts to Int8, or returns null when the value is outside Int8’s range.
fn to_int8() Int8?Int32.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?Int64 Type#
Signed 64-bit whole numbers; the same type as Int while Int is 64 bits wide.
type Int64 { ... }Int8 Type#
Signed 8-bit whole numbers (-128 to 127); arithmetic faults when the result leaves the range.
type Int8 { ... }Int8.abs#
Returns the absolute value; the most negative value has none and faults like any overflow.
fn abs() Int8Int8.clone#
Returns the value itself: a Int8 copies by value.
fn clone() Int8Int8.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other Int8) IntInt8.sign#
Returns -1, 0 or 1 as this value is negative, zero or positive.
fn sign() IntInt8.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringInt8.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalInt8.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatInt8.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32Int8.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringInt8.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntInt8.to_int16#
Converts to Int16; every value fits, so no check is needed.
fn to_int16() Int16Int8.to_int32#
Converts to Int32; every value fits, so no check is needed.
fn to_int32() Int32Int8.to_int64#
Converts to Int64; every value fits, so no check is needed.
fn to_int64() Int64Int8.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?List Native type#
An ordered mutable collection with indexing, iteration and transformations.
Start with a literal such as ["docs", "release"]; use var when you want to append, remove or replace items.
A list has one owner; clone() makes a deep copy, and xs[i] and accessors such as first borrow elements.
List[T]() creates an empty list. List[T](reserve: n) also preallocates room for n items without changing the length; a negative n reserves nothing.
type List[T] {
reserve Int? = null
}
fn List[T].is_empty() Bool { ... }
fn var List[T].prepend(move value T) Void { ... }
fn var List[T].insert(index Int, move value T) Void { ... }
fn var List[T].pop() T? { ... }
fn var List[T].set(index Int, move value T) Void { ... }
fn var List[T].replace(index Int, move value T) T { ... }
fn var List[T].swap(i Int, j Int) Void { ... }
fn var List[T].remove(index Int) Void { ... }
fn var List[T].reverse() Void { ... }
fn var List[T].sort(compare fn(T, T) Int) Void { ... }
fn var List[T].splice(start Int, delete_count Int, move replacement List[T]) Void { ... }
fn var List[T].drain(start Int, end Int) List[T] { ... }
fn var List[T].truncate(length Int) Void { ... }
fn List[T].keys() List[Int] { ... }
fn var List[T].append(move value T) Void { ... }
fn List[T].length() Int { ... }
fn List[T].clone() List[T] { ... }
fn List[T].slice(start Int, end Int) Result[List[T], Error] { ... }
fn List[T].take(count Int) List[T] { ... }
fn List[T].drop(count Int) List[T] { ... }
fn List[T].chunks(size Int) List[List[T]] { ... }
fn List[T].windows(size Int) List[List[T]] { ... }
fn List[T].sorted(compare fn(T, T) Int) List[T] { ... }
fn var List[T].fill(move value T, start Int, end Int) Void { ... }
fn var List[T].copy_within(target Int, start Int, end Int) Void { ... }
fn List[T].concat(other List[T]) List[T] { ... }
fn List[T].group_by[K Hashable](key fn(T) K) Map[K, List[T]] { ... }
fn List[T].repeated(count Int) List[T] { ... }
fn var List[T].extend(other List[T]) Void { ... }List.reserve#
Constructor-only capacity hint in items: room for this many elements is allocated
up front. The list starts empty. null or a negative value reserves nothing.
reserve Int? = nullList.all#
Reports whether every value satisfies predicate; an empty list returns true.
fn all(predicate fn(T) Bool) BoolList.any#
Reports whether at least one value satisfies predicate.
fn any(predicate fn(T) Bool) BoolList.append#
Adds value at the end in place.
var fn append(move value T) Void { ... }List.append_all#
Moves every element of other to the end of this list, in order, and consumes
other. Nothing is cloned, so it works for any element type. Example: after
var xs = [1], xs.append_all([2, 3]) leaves xs as [1, 2, 3].
var fn append_all(move other List[T]) VoidList.binary_search#
Searches in O(log n) comparisons without copying elements or changing the list.
The list must be in ascending natural order, as sorted() produces: comparisons must form a total order, with Float NaNs last.
Sortedness is not checked; a list in the wrong order gives an unspecified result.
Returns the index of the first element that compares equal, or the insertion position with found: false. An empty list returns index 0.
Example: [1, 3, 3, 5].binary_search(3).index is 1; searching for 4 gives index 3 with found: false.
// Receiver: List[T]; T Comparable
fn binary_search(value T) SearchResultList.chunks#
Splits the list into consecutive chunks of size elements, as copies. The last
chunk may be shorter. An empty list, or a size of zero or less, gives an empty
list.
fn chunks(size Int) List[List[T]] { ... }List.clear#
Removes every element in place and keeps the allocated capacity, so a scratch list can be refilled without reallocating.
var fn clear() VoidList.clone#
Returns a deep copy with independent list and nested value storage.
fn clone() List[T] { ... }List.compact#
Collapses each run of consecutive equal elements into its first element, in place. Elements must implement Equal.
Sort first to remove every duplicate, or use distinct(), which keeps the first of all equal elements without sorting.
Example: var xs = [1, 1, 2, 2, 1] then xs.compact() leaves [1, 2, 1].
// Receiver: List[T]; T Equal
var fn compact() VoidList.compact_by#
Collapses each run of consecutive elements that same calls equal into its first element, in place.
same(previous, next) receives the last kept element and the candidate, so it runs once for each element after the first.
Example: var xs = [1, 1, 2, 1] then xs.compact_by((a, b) => a == b) leaves [1, 2, 1].
var fn compact_by(same fn(T, T) Bool) VoidList.concat#
Returns a new list holding this list’s elements followed by other; neither
operand is changed.
fn concat(other List[T]) List[T] { ... }List.contains#
Reports whether any element equals value, using the element type’s Equal
implementation. An empty list returns false.
// Receiver: List[T]; T Equal
fn contains(value T) BoolList.copy_within#
Copies the elements in [start, end) to begin at index target, in place. The
list never grows: copying stops at the end of the list. Source bounds must
satisfy 0 <= start <= end <= length() and a target must be within 0 through
length(); otherwise the call faults.
var fn copy_within(target Int, start Int, end Int) Void { ... }List.count#
Counts the values for which predicate is true, calling it once per element in
order.
fn count(predicate fn(T) Bool) IntList.counts#
Counts how many times each distinct element occurs. Keys appear in first-seen order.
Example: ["a", "b", "a"].counts() maps "a" to 2 and "b" to 1.
// Receiver: List[T]; T Hashable & Clonable
fn counts() Map[T, Int]List.distinct#
Returns a new list with a copy of the first of each group of equal elements, in
order. Elements must implement Equal and be Clonable.
// Receiver: List[T]; T Equal & Clonable
fn distinct() List[T]List.drain#
Moves the elements in [start, end) out into a new list, in order, and closes the gap. Nothing is cloned, so it works for any element type. Bounds must satisfy 0 <= start <= end <= length(); otherwise the call faults.
var fn drain(start Int, end Int) List[T] { ... }List.drop#
Returns a new list with copies of the elements after the first count. The
receiver is unchanged; a count of zero or below drops nothing.
fn drop(count Int) List[T] { ... }List.drop_while#
Copies the elements from the first one that fails predicate to the end, so it is
what take_while leaves. Example: [1, 2, 5, 1].drop_while(x => x < 3) is
[5, 1].
// Receiver: List[T]; T Clonable
fn drop_while(predicate fn(T) Bool) List[T]List.entries#
Returns a new list of ListEntry records pairing each zero-based index with its
element, in order.
// Receiver: List[T]; T Clonable
fn entries() List[ListEntry[T]]List.extend#
Appends a copy of every element of other, in order, to this list in place;
other is unchanged. The argument cannot be the receiver. Example: after
var xs = [1], xs.extend([2, 3]) leaves xs as [1, 2, 3].
var fn extend(other List[T]) Void { ... }List.fill#
Sets the elements in [start, end) to copies of value in place. Bounds must
satisfy 0 <= start <= end <= length(); a negative or larger bound faults instead
of counting from the end. An empty range changes nothing.
var fn fill(move value T, start Int, end Int) Void { ... }List.filter#
Returns a new list of the values for which predicate is true, in their original
order.
// Receiver: List[T]; T Clonable
fn filter(predicate fn(T) Bool) List[T]List.find#
Returns the first element for which predicate is true as a view of this list, or
null. Later elements are not tested after a match. Use .clone() to keep it.
fn find(predicate fn(T) Bool) T?List.find_index#
Returns the zero-based index of the first element for which predicate is true,
or null.
fn find_index(predicate fn(T) Bool) Int?List.find_last#
Searches from the end and returns the last element for which predicate is true as a
view of this list, or null.
fn find_last(predicate fn(T) Bool) T?List.find_last_index#
Searches from the end and returns the last matching zero-based index, or null.
fn find_last_index(predicate fn(T) Bool) Int?List.first#
Returns the first element, or null when the list is empty.
fn first() T?List.flat_map#
Calls transform on each element in order and concatenates the returned lists
into one new list; the receiver is unchanged.
fn flat_map[U](transform fn(T) List[U]) List[U]List.fold#
Combines the values from left to right with step, starting with initial.
fn fold[A](move initial A, step fn(A, T) A) AList.fold_right#
Combines the values from right to left with step, starting with initial.
fn fold_right[A](move initial A, step fn(A, T) A) AList.for_each#
Calls operation(value) on each element in order. The traversal covers the list’s
initial length, so an append during the loop does not extend it, while element
writes can affect later calls. A callback that takes its parameter as var changes
the element in place, and the receiver must then be var; a reading callback works
on any list.
fn for_each(operation fn(var T) Void) VoidList.get_or#
Returns an element, or default when the index is out of range; negative indexes
are relative to the end.
fn get_or(index Int, default T) TList.group_by[K Hashable]#
Calls key once per element in order and returns a map from each distinct key to
the elements that produced it. Keys appear in first-seen order, and each group
keeps the original element order.
fn group_by[K Hashable](key fn(T) K) Map[K, List[T]] { ... }List.index_of#
Returns the zero-based index of the first element equal to value, or null.
Elements must implement Equal.
// Receiver: List[T]; T Equal
fn index_of(value T) Int?List.insert#
Inserts value before index in place; negative indexes count from the end.
Requires -length() <= index <= length(). An index of length() appends; any other
invalid index faults.
var fn insert(index Int, move value T) Void { ... }List.is_empty#
Reports whether the list has no elements.
fn is_empty() Bool { ... }List.is_sorted#
Reports whether the list is in ascending natural order, the order sorted()
produces; empty and one-element lists are. Example: [1, 2, 2, 5].is_sorted() is
true.
// Receiver: List[T]; T Comparable
fn is_sorted() BoolList.is_sorted_by#
Reports whether the list is already in the order compare defines, meaning no
element sorts after its successor. Empty and one-element lists are sorted.
fn is_sorted_by(compare fn(T, T) Int) BoolList.join#
Joins the elements’ interpolation text ("{value}") with separator between neighbors; an empty list returns an empty string.
Strings join as they are and numbers as decimal text. A record or alternative joins in its structural form.
Example: [1, 2, 3].join(",") is "1,2,3".
fn join(separator String) StringList.keys#
Returns a new list of the zero-based indexes 0 through length() - 1.
fn keys() List[Int] { ... }List.last#
Returns the last element, or null when the list is empty.
fn last() T?List.last_index_of#
Returns the zero-based index of the last element equal to value, or null.
Elements must implement Equal.
// Receiver: List[T]; T Equal
fn last_index_of(value T) Int?List.length#
Returns the number of elements.
fn length() Int { ... }List.map#
Returns a new list holding transform applied to each element in order; the
receiver is unchanged.
fn map[U](transform fn(T) U) List[U]List.max#
Returns the greatest element as a view of this list, or null for an empty list. The
first of equal elements wins. Example: [3, 1, 2].max() is 3.
// Receiver: List[T]; T Comparable
fn max() T?List.max_by#
Returns a view of the element whose key is greatest, or null when the list is empty.
key is called once per element in order, and ties keep the earlier element.
Example: ["bb", "a", "ccc"].max_by(w => w.length()) is "ccc".
fn max_by[K Comparable](key fn(T) K) T?List.min#
Returns the least element as a view of this list, or null for an empty list. The
first of equal elements wins. Example: [3, 1, 2].min() is 1; List[Int]().min()
is
null.
// Receiver: List[T]; T Comparable
fn min() T?List.min_by#
Returns a view of the element whose key is least, or null when the list is empty.
key is called once per element in order, and ties keep the earlier element.
Example: ["bb", "a", "ccc"].min_by(w => w.length()) is "a".
fn min_by[K Comparable](key fn(T) K) T?List.partition#
Calls predicate once per element in order and splits the elements into those
that matched and the rest, each in the original order.
// Receiver: List[T]; T Clonable
fn partition(predicate fn(T) Bool) Partition[T]List.pop#
Removes and returns the last element in place, or null for an empty list.
var fn pop() T? { ... }List.prepend#
Inserts value at index 0 in place, shifting existing elements one position
later.
var fn prepend(move value T) Void { ... }List.remove#
Removes the element at index in place; negative indexes count from the end.
Invalid indexes fault.
Later elements shift down. Values left in spare backing capacity are not cleared.
var fn remove(index Int) Void { ... }List.repeated#
Returns a new list holding the elements count times over, in order. A count of
zero or below gives an empty list. Example: [1, 2].repeated(2) is
[1, 2, 1, 2].
fn repeated(count Int) List[T] { ... }List.replace#
Stores value at index in place and returns the element that was there. Both
move without copying. Negative indexes count from the end; invalid indexes fault.
var fn replace(index Int, move value T) T { ... }List.retain#
Keeps only the elements for which keep is true, in place and in their original order. keep is called once per element, in order.
Dropped elements are closed when they are resources; kept ones are moved, not copied.
Example: var xs = [1, 2, 3, 4] then xs.retain(x => x % 2 == 0) leaves [2, 4].
var fn retain(keep fn(T) Bool) VoidList.reverse#
Reverses this list in place.
var fn reverse() Void { ... }List.reversed#
Returns an independent reversed copy, including nested values.
// Receiver: List[T]; T Clonable
fn reversed() List[T]List.rotate#
Moves every element by places toward the front in place, wrapping the first ones around to the end.
A negative by rotates toward the back, and any magnitude is reduced modulo the length. An empty list is unchanged.
Example: var xs = [1, 2, 3, 4] then xs.rotate(1) leaves [2, 3, 4, 1].
var fn rotate(by Int) VoidList.set#
Replaces an element in place; negative indexes count from the end. Invalid indexes fault.
var fn set(index Int, move value T) Void { ... }List.slice#
Returns the elements in [start, end) as a view of this list: it keeps the list
unchangeable until its last use, and nothing is copied. Use .clone() to keep it.
Negative bounds are relative to the end; bounds outside 0 <= start <= end <=
length() return an Error of kind ERANGE.
fn slice(start Int, end Int) Result[List[T], Error] { ... }List.sort#
Sorts the list in place, stably, in the order compare defines, as sorted does.
Comparable elements also have sort() without a comparator. Example:
var xs = [3, 1, 2] then xs.sort((a, b) => b - a) leaves [3, 2, 1].
var fn sort(compare fn(T, T) Int) Void { ... }List.sort#
Sorts the list in place, stably, in the same order as sorted().
Example: var xs = [3, 1, 2] then xs.sort() leaves [1, 2, 3].
// Receiver: List[T]; T Comparable
var fn sort() VoidList.sorted#
Returns a new list ordered by compare; the receiver is unchanged. The sort is stable: equal elements keep their order.
A negative, zero or positive result puts the first argument before, level with or after the second. Comparable elements also have sorted() without a comparator.
Example: names.sorted((a, b) => a.length() - b.length()) orders by length.
fn sorted(compare fn(T, T) Int) List[T] { ... }List.sorted#
Returns a new list in ascending natural order; the receiver is unchanged. The sort is stable: equal elements keep their order.
Float orders NaN above every other value.
Example: [3, 1, 2].sorted() is [1, 2, 3].
// Receiver: List[T]; T Comparable & Clonable
fn sorted() List[T]List.sorted_by_key#
Returns a new list ordered by the natural order of key(element). The receiver is
unchanged and the sort is stable. key runs on every comparison, so keep it cheap.
Example: people.sorted_by_key(p => p.age).
// Receiver: List[T]; T Clonable
fn sorted_by_key[K Comparable](key fn(T) K) List[T]List.splice#
Replaces delete_count elements starting at start in place with the elements of replacement, which is consumed.
Requires 0 <= start <= length and 0 <= delete_count <= length - start; invalid bounds fault and are not clamped.
Removed elements are dropped, and replacement elements move into the receiver. The receiver and the replacement cannot be the same list.
var fn splice(start Int, delete_count Int, move replacement List[T]) Void { ... }List.sum#
Adds the elements from left to right with + in the element type’s own
arithmetic: integer overflow faults and floats follow their width. An empty list
sums to zero.
Example: [1, 2, 3].sum() is 6; [1.5, 2.5].sum() is 4.0.
// Receiver: List[T]; T Numeric
fn sum() TList.swap#
Exchanges the elements at i and j in place without copying them; equal indexes
change nothing. Negative indexes count from the end; invalid indexes fault.
var fn swap(i Int, j Int) Void { ... }List.take#
Returns a new list with copies of the first count elements, or of all of them
when count exceeds the length. The receiver is unchanged; a count of zero or
below gives an empty list.
fn take(count Int) List[T] { ... }List.take_while#
Copies the leading elements for which predicate holds, stopping at the first one
that fails it. Example: [1, 2, 5, 1].take_while(x => x < 3) is [1, 2].
// Receiver: List[T]; T Clonable
fn take_while(predicate fn(T) Bool) List[T]List.to_set#
Returns a new set of the distinct elements, using Hashable equality. The first
of equal elements is kept, in insertion order.
// Receiver: List[T]; T Hashable & Clonable
fn to_set() Set[T]List.truncate#
Keeps the first length elements and drops the rest in place; the capacity stays.
A length at or above the current length changes nothing; a negative length
faults.
var fn truncate(length Int) Void { ... }List.windows#
Returns each run of size consecutive elements as an overlapping copy, in order.
A list shorter than size, or a size of zero or less, gives an empty list.
Windows are copies; slice and take do not borrow.
fn windows(size Int) List[List[T]] { ... }List.zip#
Pairs elements by position into fresh Pair records, stopping at the shorter
list; both lists are unchanged.
// Receiver: List[T]; T Clonable
fn zip[U Clonable](other List[U]) List[Pair[T, U]]ListEntry Type#
One list index and the value stored there.
type ListEntry[T] {
index Int
value T
}ListEntry.index#
Zero-based position of the element in the list that produced this entry.
index IntListEntry.value#
The element found at index.
value TMap Native type#
A mutable key-value collection that remembers insertion order. Keys use their
Hashable implementation to decide equality.
type Map[T Hashable, U] {
}
fn var Map[T, U].reserve(extra Int) Void { ... }
fn var Map[T, U].add_default(move key T, move value U) Void { ... }
fn var Map[T, U].clear() Void { ... }
fn Map[T, U].keys() List[T] { ... }
fn Map[T, U].contains(key T) Bool { ... }
fn Map[T, U].get(key T) U? { ... }
fn Map[T, U].length() Int { ... }
fn var Map[T, U].add(move key T, move value U) Void { ... }
fn var Map[T, U].remove(key T) Void { ... }
fn Map[T, U].values() List[U] { ... }
fn var Map[T, U].merge(other Map[T, U]) Void { ... }
fn var Map[T, U].update(key T, move initial U, change fn(U) U) Void { ... }Map.add#
Inserts or replaces a value; replacement keeps the original key and insertion position.
var fn add(move key T, move value U) Void { ... }Map.add_default#
Inserts value only when the key is absent. The argument is evaluated even when
the key already exists.
var fn add_default(move key T, move value U) Void { ... }Map.add_default_from#
Inserts create(key) only when the key is absent, calling create once. An
existing key keeps its value and position, and create is not called.
var fn add_default_from(move key T, create fn(T) U) VoidMap.all#
Reports whether every entry satisfies predicate, stopping at the first entry
that does not. An empty map returns true.
fn all(predicate fn(T, U) Bool) BoolMap.any#
Reports whether any entry satisfies predicate, stopping at the first match. An
empty map returns false.
fn any(predicate fn(T, U) Bool) BoolMap.clear#
Removes every entry in place.
var fn clear() Void { ... }Map.clone#
Returns a deep copy with independent map and nested value storage.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn clone() Map[T, U]Map.contains#
Reports whether an equal key is present, using the key type’s Hashable
implementation.
fn contains(key T) Bool { ... }Map.entries#
Returns a new list of MapEntry records in insertion order. Each record holds a copy
of its key and value.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn entries() List[MapEntry[T, U]]Map.filter#
Returns a new map of copies of the entries for which predicate is true, in
insertion order. The callback borrows the receiver, so changing the map during
the traversal is rejected.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn filter(predicate fn(T, U) Bool) Map[T, U]Map.find#
Returns the first entry for which predicate is true as a new MapEntry holding
copies of the key and value, or null.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn find(predicate fn(T, U) Bool) MapEntry[T, U]?Map.find_last#
Searches from the end and returns the last entry for which predicate is true as
a new MapEntry holding copies of the key and value, or null.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn find_last(predicate fn(T, U) Bool) MapEntry[T, U]?Map.fold#
Combines the entries in insertion order with step, starting with initial.
fn fold[A](move initial A, step fn(A, T, U) A) AMap.fold_right#
Combines the entries in reverse insertion order with step, starting with
initial.
fn fold_right[A](move initial A, step fn(A, T, U) A) AMap.for_each#
Calls operation(key, value) for each entry in insertion order.
A callback that takes value as var changes it in place, and the receiver must
then be var.
// Receiver: Map[T, U]; T Hashable
fn for_each(operation fn(T, var U) Void) VoidMap.get#
Returns the value stored for an equal key, or null when the key is absent.
fn get(key T) U? { ... }Map.get_or#
Returns the stored value, or fallback when the key is absent, as a view of
whichever it is. The fallback is always evaluated, and the map is not changed. Use
.clone() to keep the result.
// Receiver: Map[T, U]; T Hashable
fn get_or(key T, fallback U) UMap.is_empty#
Reports whether this map has no entries.
fn is_empty() BoolMap.keys#
Returns the keys in insertion order as a view of this map: it keeps the map
unchangeable until its last use. Use .clone() to keep the keys.
fn keys() List[T] { ... }Map.length#
Returns the number of entries.
fn length() Int { ... }Map.map#
Returns a new map with the same keys, each paired with transform(key, value), in
insertion order. Keys are copied into the new map.
// Receiver: Map[T, U]; T Clonable
fn map[W](transform fn(T, U) W) Map[T, W]Map.map_keys#
Returns a new map with each key replaced by transform(key, value), in insertion
order, and the values copied. When two entries produce equal keys, the result keeps
the first position and the last value.
// Receiver: Map[T, U]; T Hashable & Clonable, U Clonable
fn map_keys[W Hashable](transform fn(T, U) W) Map[W, U]Map.merge#
Copies every entry of other into this map in place. Existing keys keep their
position and key but take the value from other; new keys append in other
order. other is unchanged.
var fn merge(other Map[T, U]) Void { ... }Map.remove#
Removes an equal key in place; the remaining entries keep their insertion order. An absent key changes nothing.
var fn remove(key T) Void { ... }Map.reserve#
Makes room for extra more entries beyond the current length, so adding them does
not rehash. The entries are unchanged; extra of zero or below does nothing.
var fn reserve(extra Int) Void { ... }Map.retain#
Keeps only the entries for which keep(key, value) is true, in place, like List.retain. The rest keep their insertion order.
keep is called once per entry in insertion order, before any removal.
Example: cache.retain((key, hits) => hits > 0) evicts unused entries.
// Receiver: Map[T, U]; T Hashable & Clonable
var fn retain(keep fn(T, U) Bool) VoidMap.update#
Stores change applied to the value for key, or to initial when the key is
absent. The key is probed once, initial is always evaluated, and change runs once
and must not use this map. The key is copied only when it is absent. Example:
counts.update(word, 0, n => n + 1) counts occurrences.
var fn update(key T, move initial U, change fn(U) U) Void { ... }Map.values#
Returns the values in insertion order as a view of this map: it keeps the map
unchangeable until its last use. Use .clone() to keep the values.
fn values() List[U] { ... }MapEntry Type#
One key-value pair returned by Map.entries.
type MapEntry[T Hashable, U] {
key T
value U
}MapEntry.key#
The key; unique within its map under Hashable equality.
key TMapEntry.value#
The value stored for key. Reading this field borrows from the entry.
value UNever Type#
The return type of computations that cannot return a value, such as panic.
type Never { ... }Optional Enum#
Represents a value that may be absent: a T or null; a plain T converts where a
T? is expected.
enum Optional[T] {
some(value T)
null
}Optional.null#
An absent value with no payload; no T needs to be constructed.
nullOptional.some#
A present payload, retained by reference when T is mutable.
some(value T)Optional.some.value#
The contained value; unwrap and matching return this original payload.
value TOptional.clone#
An Optional copies its payload; null stays null.
// Receiver: T?; T Clonable
fn clone() T?Result Enum#
Holds either a successful value (ok) or an expected failure (error).
enum Result[T, E] {
ok(value T)
error(cause E)
}Result.error#
An expected failure value; it is distinct from faults and cancellation.
error(cause E)Result.ok#
A successful result, retaining its payload without a deep copy.
ok(value T)Result.error.cause#
The original domain error, retained through compatible Result propagation.
cause EResult.ok.value#
The successful value returned by unwrap, matching, or propagation.
value TResult.and_then#
Calls transform only on success and returns the Result it produces; an error
passes through. The error type stays the same.
move fn and_then[U](transform fn(move T) Result[U, E]) Result[U, E]Result.err#
Returns the error payload; check is_error() first, because a successful result
raises a fault.
fn err() EResult.get#
Returns the successful payload; an error raises a fault, so use it only when
failure is a bug. Prefer ?, if value := result: or get_or(default).
fn get() TResult.get_or#
Returns the successful payload, or default when this is an error. The default is
always evaluated; use get_or_else when it costs work.
move fn get_or(move default T) TResult.get_or_else#
Returns the successful payload; for an error, calls create once with that error
and returns its value.
move fn get_or_else(create fn(move E) T) TResult.is_error#
Reports whether this result contains an expected error.
fn is_error() BoolResult.is_ok#
Reports whether this result contains a successful value.
fn is_ok() BoolResult.map#
Transforms only a successful payload, preserving an error unchanged.
move fn map[U](transform fn(move T) U) Result[U, E]Result.map_error#
Transforms only an error, preserving a successful payload unchanged.
move fn map_error[F](transform fn(move E) F) Result[T, F]Result.or_else#
Returns this result when it is successful; for an error, calls create once with
that error and returns the Result it produces.
move fn or_else(create fn(move E) Result[T, E]) Result[T, E]Result.to_optional#
Returns some with the original success payload, or null for an error.
move fn to_optional() T?Set Native type#
A mutable collection of unique values that remembers insertion order. Values use
their Hashable implementation to decide equality.
type Set[T Hashable] {
}
fn Set[T].union(other Set[T]) Set[T] { ... }
fn Set[T].intersection(other Set[T]) Set[T] { ... }
fn Set[T].difference(other Set[T]) Set[T] { ... }
fn Set[T].symmetric_difference(other Set[T]) Set[T] { ... }
fn Set[T].is_subset_of(other Set[T]) Bool { ... }
fn Set[T].is_superset_of(other Set[T]) Bool { ... }
fn Set[T].is_disjoint_from(other Set[T]) Bool { ... }
fn var Set[T].clear() Void { ... }
fn var Set[T].reserve(extra Int) Void { ... }
fn Set[T].values() List[T] { ... }
fn Set[T].contains(value T) Bool { ... }
fn Set[T].length() Int { ... }
fn var Set[T].add(move value T) Void { ... }
fn var Set[T].remove(value T) Void { ... }Set.add#
Adds a value in place. If an equal value is already present, it keeps its original value and position.
var fn add(move value T) Void { ... }Set.all#
Reports whether every element satisfies predicate, stopping at the first one
that does not. An empty set returns true.
fn all(predicate fn(T) Bool) BoolSet.any#
Reports whether any element satisfies predicate, stopping at the first match. An
empty set returns false.
fn any(predicate fn(T) Bool) BoolSet.clear#
Removes all values in place.
var fn clear() Void { ... }Set.clone#
Returns a deep copy with independent storage, in the same insertion order.
// Receiver: Set[T]; T Hashable & Clonable
fn clone() Set[T]Set.contains#
Reports whether an equal value is present, using the element’s Hashable
implementation.
fn contains(value T) Bool { ... }Set.difference#
Returns a new set of this set’s values that are not in other, in this set’s
insertion order.
fn difference(other Set[T]) Set[T] { ... }Set.filter#
Returns a new set of copies of the elements for which predicate is true, in
insertion order. The callback borrows the receiver, so changing the set during the
traversal is rejected.
// Receiver: Set[T]; T Hashable & Clonable
fn filter(predicate fn(T) Bool) Set[T]Set.find#
Returns a copy of the first element for which predicate is true, or null.
// Receiver: Set[T]; T Hashable & Clonable
fn find(predicate fn(T) Bool) T?Set.find_last#
Searches from the end and returns a copy of the last element for which predicate is
true, or null.
// Receiver: Set[T]; T Hashable & Clonable
fn find_last(predicate fn(T) Bool) T?Set.fold#
Combines the elements in insertion order with step, starting with initial.
fn fold[A](move initial A, step fn(A, T) A) ASet.fold_right#
Combines the elements in reverse insertion order with step, starting with
initial.
fn fold_right[A](move initial A, step fn(A, T) A) ASet.for_each#
Calls operation(value) for each value in insertion order.
fn for_each(operation fn(T) Void) VoidSet.intersection#
Returns a new set of this set’s values that are also in other, in this set’s
insertion order.
fn intersection(other Set[T]) Set[T] { ... }Set.is_disjoint_from#
Reports whether the two sets have no value in common.
fn is_disjoint_from(other Set[T]) Bool { ... }Set.is_empty#
Reports whether this set has no elements.
fn is_empty() BoolSet.is_subset_of#
Reports whether every value of this set is also in other.
fn is_subset_of(other Set[T]) Bool { ... }Set.is_superset_of#
Reports whether every value of other is also in this set.
fn is_superset_of(other Set[T]) Bool { ... }Set.length#
Returns the number of distinct values currently stored.
fn length() Int { ... }Set.map#
Returns a new set of transform(element) for each element; when results are
equal, the first is kept.
fn map[U Hashable](transform fn(T) U) Set[U]Set.remove#
Removes an equal value in place; an absent value changes nothing.
var fn remove(value T) Void { ... }Set.reserve#
Makes room for extra more values beyond the current length, so adding them does not
rehash. The values are unchanged; extra of zero or below does nothing.
var fn reserve(extra Int) Void { ... }Set.retain#
Keeps only the values for which keep is true, in place, like List.retain. The
rest keep their insertion order. Example: seen.retain(n => n >= 0).
// Receiver: Set[T]; T Hashable & Clonable
var fn retain(keep fn(T) Bool) VoidSet.symmetric_difference#
Returns a new set of the values that are in exactly one of the two sets. Neither set changes.
fn symmetric_difference(other Set[T]) Set[T] { ... }Set.union#
Returns a new set with this set’s values followed by the values only in other,
in insertion order.
fn union(other Set[T]) Set[T] { ... }Set.values#
Returns a new list of copies of the values in insertion order.
fn values() List[T] { ... }String Type#
UTF-8 text addressed by byte offsets; length is bytes, scalar_length counts Unicode scalars, and chars() walks scalars.
type String { ... }String.as_bytes#
The UTF-8 encoding of the text.
fn as_bytes() BytesString.capitalize#
Converts the first scalar to its titlecase form (dž becomes Dž, ß becomes
Ss) and leaves the rest unchanged.
fn capitalize() StringString.chars#
Returns a list with one String for each Unicode scalar, in order. The result
borrows the receiver: use it in place, or .clone() it to keep it.
fn chars() List[String]String.compare#
Returns -1, 0 or 1 in lexical scalar order, without locale or normalization.
fn compare(other String) IntString.concat#
Concatenates text without changing either operand.
fn concat(other String) StringString.contains#
Tests whether the exact text occurs, without normalization.
fn contains(value String) BoolString.contains_any#
Reports whether any scalar of set occurs in the text.
fn contains_any(set String) BoolString.count#
Counts non-overlapping occurrences; an empty part counts the scalars plus one.
fn count(part String) IntString.cut_prefix#
Returns the text without prefix as a view, or null when the text does not start
with it. An empty prefix succeeds and returns the text unchanged.
fn cut_prefix(prefix String) String?String.cut_suffix#
Returns the text without suffix as a view, or null when the text does not end
with it. An empty suffix succeeds and returns the text unchanged.
fn cut_suffix(suffix String) String?String.display_width#
Returns the number of terminal columns the text occupies. Combining marks add
nothing, ambiguous-width characters count as narrow, and wide characters and
supported emoji sequences count two. This is an estimate, not a promise for every
font or terminal. Controls (tabs, CR/LF, ESC, C1), U+2028 and U+2029 return
EBADMSG.
fn display_width() Result[Int, Error]String.ends_with#
Tests whether the receiver ends with this exact suffix.
fn ends_with(suffix String) BoolString.equal_fold#
Compares text ignoring case. Both sides are uppercased and then lowercased with Unicode full case mapping, without locale or normalization, so “Straße” equals “STRASSE”. This is not Unicode default case folding: the dotless “ı” (U+0131) uppercases to “I”, so it compares equal to “i” and “I”.
fn equal_fold(other String) BoolString.fields#
Splits on runs of Unicode White_Space and omits empty fields, so empty or
all-whitespace text gives an empty list. Field text is kept exactly, without
normalization. The byte-order mark and zero-width space are not separators. The
fields borrow the receiver, as split pieces do: use them in place, or .clone()
the result.
fn fields() List[String]String.fields_by#
Splits around runs of characters (one-scalar strings) for which is_separator
returns true. The result has no empty items.
fn fields_by(is_separator fn(String) Bool) List[String]String.find_char#
Returns the byte offset of the first scalar (passed as a one-scalar string) for
which predicate returns true, or null.
fn find_char(predicate fn(String) Bool) Int?String.index_any#
Returns the byte offset of the first scalar that occurs in set, or null.
fn index_any(set String) Int?String.index_of#
Returns the byte offset of the first match, or null. An empty value matches
at zero.
fn index_of(value String) Int?String.into_bytes#
Returns the UTF-8 bytes and consumes the text. A heap string hands over its buffer
without a copy; as_bytes borrows and copies instead.
move fn into_bytes() BytesString.is_empty#
Reports whether the text contains no bytes.
fn is_empty() BoolString.last_index_of#
Returns the byte offset of the last match, or null. An empty value matches at
length().
fn last_index_of(value String) Int?String.length#
The UTF-8 byte length, in constant time.
fn length() IntString.lines#
Splits at LF and CRLF, keeping interior empty lines and any standalone CR.
Text that ends in a newline yields no extra empty item, and empty text returns
an empty list. The result borrows the receiver: use it in place, or .clone()
it to keep it.
fn lines() List[String]String.lower#
Returns the text in full Unicode lowercase, independent of locale. The scalar length can change.
fn lower() StringString.map_chars#
Replaces each scalar (a one-scalar string) with the result of transform; an
empty result deletes it.
fn map_chars(transform fn(String) String) StringString.normalize#
Normalizes to the form named by form, which must be exactly "NFC", "NFD",
"NFKC" or "NFKD". max_bytes optionally bounds the UTF-8 output. An invalid
form or negative bound returns EINVAL; exceeding the bound returns EOVERFLOW.
fn normalize(form String, max_bytes Int? = null) Result[String, Error]String.pad_end#
Pads on the right until the scalar length reaches target_length; see pad_start.
fn pad_end(target_length Int, padding String = " ") StringString.pad_start#
Pads on the left (pad_start) or the right (pad_end) until the scalar length
reaches target_length, repeating padding and cutting its last copy.
fn pad_start(target_length Int, padding String = " ") StringString.parse_bool#
Parses a boolean after trimming whitespace and ignoring case. true, t, 1,
yes and on give true; false, f, 0, no and off give false. Anything
else is null.
fn parse_bool() Bool?String.parse_float#
Parses a decimal floating-point number with the syntax of math.parse_float;
invalid or out-of-range text returns null.
fn parse_float() Float?String.parse_int#
Parses signed ASCII decimal digits; invalid text or Int overflow returns null.
fn parse_int() Int?String.repeat#
Repeats the text count times. A count of zero or below, or empty text, gives
empty text. Output beyond the string limit faults, as concat does.
fn repeat(count Int) StringString.replace#
Replaces every nonoverlapping occurrence of old, scanning left to right; inserted text is not rescanned.
An empty old matches at each scalar boundary, so "ab".replace("", "-") is "-a-b-".
Output beyond the string limit faults, as concat does; use Regex.replace_all for a bounded replacement.
fn replace(old String, new String) StringString.replace_each#
Replaces many patterns in one pass. At each position the first pair, in map order, whose key matches wins, and its replacement is not rescanned. Empty keys are ignored.
fn replace_each(pairs Map[String, String]) StringString.replace_first#
Replaces the first occurrence of old; text without a match is unchanged. An
empty old matches at the start, so new is inserted there.
fn replace_first(old String, new String) StringString.reserve#
Preallocates room for at least bytes total UTF-8 bytes so subsequent += appends
avoid repeated reallocations. The text is unchanged; a non-positive or small count
does nothing, and large hints are capped like List(reserve:).
var fn reserve(bytes Int) VoidString.reverse#
Reverses the order of Unicode scalars, so a combining sequence or grapheme cluster can come out reordered.
fn reverse() StringString.rsplit_once#
Splits at the last exact separator. Returns null when the separator is empty or
does not occur.
Example: "a/b/c".rsplit_once("/") is before: "a/b", after: "c".
fn rsplit_once(separator String) SplitParts?String.scalar_at#
Returns the Unicode scalar value that starts at byte offset. An offset outside
the text or inside a scalar returns default, and without one raises a fault.
fn scalar_at(offset Int, default Int? = null) IntString.scalar_length#
Counts the Unicode scalar values by scanning the text.
fn scalar_length() IntString.scalar_values#
Returns each Unicode scalar value as an integer.
fn scalar_values() List[Int]String.slice#
Copies the bytes [start, end); negative bounds are relative to the end. Bounds
outside the text clamp to it, and a start at or past the end gives "". A bound
inside a scalar moves inward (start forward, end backward), so the result is
always whole characters. The call never fails and leaves the receiver unchanged.
fn slice(start Int, end Int) StringString.split#
Splits at every exact separator, keeping empty pieces. Empty text with a nonempty
separator yields [""]; an empty separator splits into scalars. The pieces
borrow the receiver: use them in place, or .clone() the result to keep it.
fn split(separator String) List[String]String.split_after#
Splits after each separator and keeps the separator at the end of each piece. An empty separator splits into scalars.
fn split_after(separator String) List[String]String.split_once#
Splits at the first exact separator. Returns null when the separator is empty or
does not occur.
Example: "key=a=b".split_once("=") is before: "key", after: "a=b".
fn split_once(separator String) SplitParts?String.starts_with#
Tests whether the receiver begins with this exact prefix.
fn starts_with(prefix String) BoolString.title#
Titlecases the first letter of each word and lowercases the rest. A word is a run
of letters, digits and apostrophes. Each word is lowercased as a whole, so a final
sigma stays final (ΑΣ becomes Ας).
fn title() StringString.to_bytes#
Encodes the string as UTF-8 bytes.
fn to_bytes() BytesString.to_string#
A String is its own text.
fn to_string() StringString.trim#
Removes Unicode whitespace at both ends. The exact set is listed in the text
guide. The result borrows the receiver, as view does: use it in place, or
.clone() it to keep the text.
fn trim() StringString.trim_chars#
Removes every leading and trailing scalar that occurs in set.
fn trim_chars(set String) StringString.trim_end#
Removes Unicode whitespace at the end; borrows the receiver.
fn trim_end() StringString.trim_end_chars#
Removes every trailing scalar that occurs in set.
fn trim_end_chars(set String) StringString.trim_start#
Removes Unicode whitespace at the start; borrows the receiver.
fn trim_start() StringString.trim_start_chars#
Removes every leading scalar that occurs in set.
fn trim_start_chars(set String) StringString.upper#
Returns the text in full Unicode uppercase, independent of locale. The scalar length can change.
fn upper() StringString.view#
Borrows the bytes [start, end) of the receiver without copying; negative bounds
are relative to the end. Bounds outside 0 <= start <= end <= length(), or inside
a scalar, raise a fault. Like Bytes.view, the result borrows the receiver,
which cannot change while the view is used; .clone() keeps the text. Use
slice for a copy.
fn view(start Int, end Int) StringString.view_bytes#
Borrows the UTF-8 bytes of the text without copying. Like view, the result
borrows the receiver, which cannot change while the bytes are used; .clone()
keeps them. Use to_bytes for a copy.
fn view_bytes() BytesStringable Interface#
A type with its own text form. f"{value}", print and a container’s text use
to_string when a record or alternative has one; the operation must return a
String. Every standard type with a text form meets this interface the same way, by
declaring to_string.
interface Stringable {
fn to_string() String
}Stringable.to_string#
Returns this value as text.
fn to_string() StringUInt16 Type#
Unsigned 16-bit whole numbers (0 to 65535); arithmetic faults when the result leaves the range.
type UInt16 { ... }UInt16.clone#
Returns the value itself: a UInt16 copies by value.
fn clone() UInt16UInt16.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other UInt16) IntUInt16.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringUInt16.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalUInt16.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatUInt16.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32UInt16.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringUInt16.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntUInt16.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?UInt16.to_uint8#
Converts to UInt8, or returns null when the value is outside UInt8’s range.
fn to_uint8() UInt8?UInt32 Type#
Unsigned 32-bit whole numbers (0 to 4294967295); arithmetic faults when the result leaves the range.
type UInt32 { ... }UInt32.clone#
Returns the value itself: a UInt32 copies by value.
fn clone() UInt32UInt32.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other UInt32) IntUInt32.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringUInt32.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalUInt32.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatUInt32.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32UInt32.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringUInt32.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntUInt32.to_int32#
Converts to Int32, or returns null when the value is outside Int32’s range.
fn to_int32() Int32?UInt32.to_int64#
Converts to Int64; every value fits, so no check is needed.
fn to_int64() Int64UInt32.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?UInt64 Type#
Unsigned 64-bit whole numbers (0 to 18446744073709551615); arithmetic faults when the result leaves the range.
type UInt64 { ... }UInt64.clone#
Returns the value itself: a UInt64 copies by value.
fn clone() UInt64UInt64.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other UInt64) IntUInt64.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringUInt64.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalUInt64.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatUInt64.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32UInt64.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringUInt64.to_int#
Converts to Int, or returns null when the value is above Int’s maximum.
fn to_int() Int?UInt64.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?UInt64.to_uint32#
Converts to UInt32, or returns null when the value is outside UInt32’s range.
fn to_uint32() UInt32?UInt64.to_uint8#
Converts to UInt8, or returns null when the value is outside UInt8’s range.
fn to_uint8() UInt8?UInt8 Type#
Unsigned 8-bit whole numbers (0 to 255); arithmetic faults when the result leaves the range.
type UInt8 { ... }UInt8.clone#
Returns the value itself: a UInt8 copies by value.
fn clone() UInt8UInt8.compare#
Returns -1, 0 or 1 as this value is less than, equal to or greater than other.
fn compare(other UInt8) IntUInt8.to_binary#
Formats the integer in base 2 with a leading - for negatives, as
to_string_radix(2) does; it cannot fail.
fn to_binary() StringUInt8.to_decimal#
Converts to the exactly equal Decimal; no rounding occurs.
fn to_decimal() DecimalUInt8.to_float#
Converts to the nearest Float; integers beyond 2^53 in magnitude can lose low-order digits.
fn to_float() FloatUInt8.to_float32#
Converts to Float32, rounding to the nearest binary32 value.
fn to_float32() Float32UInt8.to_hex#
Formats the integer in base 16 using lowercase digits and a leading - for
negatives, as to_string_radix(16) does; it cannot fail.
fn to_hex() StringUInt8.to_int#
Converts to Int; every value fits, so no check is needed.
fn to_int() IntUInt8.to_string_radix#
Formats the integer in a radix from 2 through 36 using lowercase digits and a
leading - for negatives, or null when the radix is outside 2 through 36.
fn to_string_radix(radix Int) String?Void Type#
The single value void, used when an operation returns no useful payload.
type Void { ... }