Index:
Tools to document module exports.
print_generator(inner_generator)Create a generator that prints the result of inner_generator to stdout.
single_page_markdown()Create a documentation generator that results in a single string of markdown.
single_page_html()Create a documentation generator that results in a single string of HTML.
generate(generator)Generate documentation using generator for all items already added to the registry.
generatorThe interface for a documentation generator.
moduleCreate an object to document members of a module.
A trait is a reusable set of methods that can be used to extend the behavior of a type. It’s an interface that defines a contract that must be implemented by any type that wishes to support the trait. Any objects that implement the trait can be converted to a trait object, which can be used to call the methods defined by the trait.
For example, you can define a Printable trait with a method print():
let Printable = trait::new("Printable", [trait::method("print")]);
trait::impl(Printable, MyType, struct {
function print(self) {
println("MyType ", self.value);
}
});
# Both equivalent:
Printable.print(MyType { value = 42 });
trait::cast(Printable, MyType { value = 42 }).print();
implements(obj, trait)Check if an object implements a trait.
If obj is a trait object, implements will return true if its trait is
trait. Otherwise return true if obj implements the trait and could be cast
to a trait object for trait.
downcast(traitobject)Retrieve the underlying object from a trait object.
impl(trait, type, implementation)Implement a trait for some type.
The implementation should be a struct containing methods for each method
defined in the trait. For example:
trait::impl(ToString, MyType, struct {
function to_string(self) {
# ...
}
});
primitive(typename)Used to specify a primitive type like "string" as the implementor of a trait. Example:
trait::impl(ToString, trait::primitive("string"), struct {
function to_string(self) {
return self;
}
});
cast(trait, obj)Create a trait object for the given trait and object.
obj must be an object that implements the trait. Any trait methods can be
called directly on the trait object.
new(name, methods)Create a new trait with the given name and methods.
Any implementors must define all methods, though the signature of the methods is not checked.
method(name)Create a trait method declaration for use with trait::new()
Functions for working with arrays.
get(array, index, fallback=null)If index is out of array’s bounds, return fallback. Otherwise return the element of array at index.
copy(array)Create a shallow copy of array.
slice(array, start, end=...)Returns a slice of array starting at index start and ending at index end. end defaults to the end of the array.
reversed(array)Create a new array with the elements of array reversed.
reverse(array)Reverse array in place.
foldl(array, init, reducer)Reduce array from the left, using the first value of array as the initial
value for the accumulator.
foldl(array, init, reducer)Reduce array from the left, using init as the initial value for the
accumulator.
map(array, func)Create a new array where each element is the result of calling func on the
corresponding element of array.
contains(array, thing)Returns true if any element of array is equal to thing.
foreach(array, func)Call func with the element, index, and array for each element of array.
find(array, predicate)Find the element for which predicate returns true. If there is none, returns null.
find_index(array, predicate)Find the index of the element for which predicate returns true. If there is none, returns -1.
collectorA collector for converting an iterator into an array.
length(array)Get the length of array array.
new(len, init=null)Create a new array of length len. Each element is initialized to init.
A doubly-linked list implementation.
foldl(list, init, reducer)Reduce the list from the left.
to_array(list)Create a new array with the elements of list.
map(list, func)Create a new linked list where every element is calculated by calling func on the old element.
collectorA collector to convert an iterator into a list.
reverse(list)Make a new linked list that is the reverse of list.
find(list, func)Return the first element of list that satisfies the predicate func.
If none is found, this function returns null.
foreach(list, func)Call func for every element of list.
get(list, i)Get the ith element from list. Throw if i is out of bounds.
Note that this function is O(n).
unshift(list)Remove and return the first element from list. If list is empty throw an Error.
pop(list)Remove and return the last element from list. If list is empty throw an Error.
append(list, value)Append value to the end of list.
prepend(list, value)Insert value at the front of list
length(list)Get the length of the list.
new()Create a new, empty linked list.
Math functions.
log10(n)Computes base-10 log of n.
log2(n)Computes base-2 log of n.
log(n)Computes base-e log of n.
min(a, b)Return the lesser of a and b.
max(a, b)Return the greater of a and b.
floor(n)Round n down to the previous integer value.
ceil(n)Round n up to the next integer value.
shr(a, b)Shift a to the right by b bits.
shl(a, b)Shift a to the left by b bits.
sqrt(n)Calculate the square root of n.
abs(n)Calculate the absolute value of n.
Functions that wrap operators.
bxor(a, b)Performs a ^ b.
bor(a, b)Performs a | b.
band(a, b)Performs a & b.
mod(a, b)Performs a % b.
div(a, b)Performs a / b.
mul(a, b)Performs a * b.
neg(a)Performs -a.
sub(a, b)Performs a - b.
add(a, b)Performs a + b.
gte(a, b)Performs a >= b.
gt(a, b)Performs a > b.
lte(a, b)Performs a <= b.
lt(a, b)Performs a < b.
ne(a, b)Performs a != b.
eq(a, b)Performs a == b.
Lazy iterators.
slice(it, start, end=...)peekable(it)sum(it)Sum the elements of it.
intersperse(it, val)Yield val in between each element of it.
repeat(val, n)Create an iterator that repeats val n times.
min(it)Find the smallest item in the iterator (using <).
max(it)Find the largest item in the iterator (using >).
fold(reducer, it, init)Reduce the iterator, using init as the initial value of the accumulator.
fold1(reducer, it)Reduce the iterator, using the first value as the initial value of the accumulator.
flat(it)Flattens an iterator of iterators.
zip(a, b)Create an iterator that joins a and b pair-wise.
take_while(it, pred)Create an iterator that yields the values of it until pred returns false.
drop(it, n)Create an iterator that ignores the first n elements of it.
Note that calling this function immediately evaluates and drops the first n
values of it.
take(it, n)Create an iterator that evaluates the first n elements of it.
Note that evaluating this iterator partially evalutaes it.
map(it, fn)Return a new iterator that yields the values of it applied to fn.
collect(it)Evaluate an iterator, returning an array of the values it yields.
foreach(it, fn)Call the function fn for every element of it. This evaluates the iterator.
enumerate(it)Create an iterator that yields pairs of index and value from it.
range(to)Create an iterator that counts from 0 to to.
count(n)Create an iterator that counts up from n indefinitely.
finalize()Finalizes the collection by returning the reduced result.
reduce()Reduces the iterator into the collection by adding an item.
init()Initializes the collection for reduction.
CollectorA trait for converting an iterator into an arbitrary collection.
next()Returns the next value in the sequence, or STOP if there are no more values.
IteratorA trait for objects that can produce a sequence of values.
iter()Returns an iterator for the object.
IterableA trait for objects that can be iterated over.
STOPA sentinel value indicating that an iterator has been exhausted.
A growable array.
contains(list, thing)Check if any element in list is equal to thing.
some(list, func)Check if any element in list satisfies the predicate func.
find(list, func)Get the first element that satisfies the predicate func, or null if none exists.
map(list, func)Create a new arraylist where each element is the result of calling func on
the corresponding element of list.
find_index(list, func)Get the index of the first element that satisfies the predicate func, or -1
if none exists.
foreach(list, func)Call func for each element of list.
pop(list)Remove and return the last element of list.
collectorA collector for converting an iterator into an arraylist.
push(list, value)Push value on to the end of list, growing it if necessary.
to_array(list)Copy the elements of list into a fixed-length array.
delete(list, idx)Remove the element at index idx from list. This involves shuffling all
elements after idx leftward, so it’s not very efficient.
set(list, idx, value)Set the element of list at index idx to value.
get(list, idx)Get the element of list at index idx.
capacity(list)Get the maximum number of items list can hold.
length(list)Get the number of items in list.
new()Create an empty arraylist with default initial capacity.
with_capacity(cap)Create an empty arraylist with the given initial capacity.
from_array(len, array)Create a new arraylist from array. The len argument should be the length
of array.
A map data structure backed by an arraylist of key-value pairs.
entries(list)Get all entries from list.
is_empty(list)Check if list has no elements.
has(list, key)Check if an entry for key exists in list.
delete(list, key)Delete the first entry for key in list.
get(list, key)Get the first value of key in list.
set(list, key, value)Set the value of key in list to value.
collectorA collector for converting an iterator of entries into an assoclist.
lengthCheck the number of items in the list.
newCreate an empty assoclist.
A compact byte array type.
collectorA collector for converting an iterator into byte array.
length(bytes)Get the length of bytes.
set(bytes, i, val)Set the ith value in bytes to val.
get(bytes, i)Get the ith element from bytes.
copy(from, to, n)Copy n bytes from from to to.
new(size)Create a new byte array of size size.
Functions for working with characters.
from_digit(c)Get the character that represents the digit n.
to_digit(c)Get the integer value of the digit character c.
to_lowercase(c)Return the lowercase version of c.
to_uppercase(c)Return the uppercase version of c.
is_whitespace(c)Check if c is an ASCII whitespace character.
is_uppercase(c)Return true if c is lowercase.
is_uppercase(c)Return true if c is uppercase.
is_alpha(c)Return true if c is an ASCII letter.
is_digit(c)Return true if c is an ASCII digit.
Functional programming utilities.
chain(functions)The same as compose, except the values are piped left-to-right.
compose(functions)Pipe the function return values from right-to-left.
For example, compose([a, b, c])("test") is equivalent to a(b(c("test"))).
partial(fn, args)Honestly not really sure what this does lol
curry(fn, a)Return a fn partially-applied with a.
flip(f)Return a function g(a, b) which calls f(b, a).
identity(x)Return x.
apply(func, args)Call func, passing as arguments the elements of the array args.
Functions for working with strings.
padright(string, padchar, len)Pad string to length len by adding padchar to the right.
padleft(string, padchar, len)Pad string to length len by adding padchar to the left.
to_lowercase(string)Convert string to lower case.
join(strings, sep)Join all strings together with sep in between each.
split(string, on)Break a string into an array of parts, where each part is separated by on.
strip(string, lpred=char::is_whitespace, rpred=null)Remove characters from both ends of the string while predicates remain true.
If only lpred is passed it’s used for the start and end of the string.
If rpred is also passed, it’s used for the end of the string.
rstrip(string, pred=char::is_whitespace)Remove characters from the end of the string while pred remains true.
lstrip(string, pred=char::is_whitespace)Remove characters from the start of the string while pred remains true.
contains(string, c)Check if string contains the character c.
rindex(string, c)Find the last index where c is found in string.
index(string, c)Find the first index where c is found in string.
endswith(string, suffix)Check if suffix is a suffix of string.
startswith(string, prefix)Check if prefix is a prefix of string.
slice(string, start, end)Get a substring of string starting from start and ending at end.
parse_float(str)Parse str as a floating point number.
parse_integer(str, base)Parse str as an integer of base base. Currently only works for base 10.
collectorA collector to convert an iterator of characters or strings into a string.
from_bytes(bytes)Convert a byte array to a string.
length(string)Get the length of string.
concat(a, ...)Concatenate all strings passed as arguments with no separator.
bytes(string)Get the bytes of string as an array.
from_chars(chars)Create a string from the array of characters chars.
chars(string)Get the characters of string as an array.
Testing utilities.
assert(cond)Throws if cond is not truthy.
AssertionErrorError raised when an assertion fails.
Base64 encoding and decoding functions.
encode(payload, out=null)Encode an array of bytes into a base64 string. A single out buffer can be reused between calls to encode for better performance.
decode(data)Decode a base64 string into an array of ints.
decode_size(payload)Calculate the number of bytes that will result from decoding payload.
encode_size(payload)Calculate the size of the base64 encoding of the byte array payload.
A simple wrapper type to emulate references.
get(self)Get the value that’s inside the box.
set(self, value)Change the value in the box to value.
new(value)Make a new box containing value.
Filesystem operations.
Lower-level functions and constants are exported from _fs.
These are not documented, and will eventually move here.
issock(path)Check if path points to a socket.
islink(path)Check if path points to a link.
isdir(path)Check if path points to a directory.
isfile(path)Check if path points to a file.
directory_entries(path)Get an iterator over the entries of a directory, excluding ‘.’ and ‘..’.
read_file(name)Read the file called fname to completion.
This should also work with fifos and stuff.
Hashing functions.
primitive(value)A hash function for primitive types.
bool(b)A hash function for booleans.
string(s)A hash function for strings.
char(c)A hashing function for character values.
int(n)A hashing function for integer values.
fnv1a(bytes)Applies the 32bit FNV-1a hashing algorithm to a byte array.
An implementation of a hash map.
extend(map, entries)Add each key-value pair in the entries iterator to map.
from_entries(entries, options=...)Create a new hashmap with the given options, and populate it from the
iterator of key-value pairs entries.
make(init, options=...)Make a new hashmap with hash as its hash functions, and call init to
initialize the map.
The init function receives a function that can be called with a key and value
to set them on the new map.
values(map)Get an iterator over the values in map.
keys(map)Get an iterator over the keys in map.
size(map)Return the number of values in map.
entries(map)Get an iterator over the key-value pairs in map.
has(map, key)Check if map has a value for key.
delete(map, key)Delete key from map.
set(map, key, value)Set the value associated with key in map to value.
get(map, key)Get the value associated with key from map.
clear(map)Delete all values from the map.
new(options=...)Create a hashmap in the default configuration. Pass options to override the defaults.
collector(options=...)Create a collector for converting an iterator of entries into a hashmap.
A partial implementation of a JSON parser.
serialize(obj)Serialize an object to JSON.
parse(input)Parse the string input as JSON.
UnserializeableErrorError raised when trying to serialize something that can’t be represented in JSON.
InvalidJsonErrorError raised when the input string is not able to be parsed.
UnexpectedTokenErrorError raised when an unexpected token is encountered.
A simple object system.
setattr(obj, name)Set an attribute on the internal dictionary of obj.
getattr(obj, name)Get an attribute from the internal dictionary of obj.
super(obj, msg, args)Call the method msg on the superclass object of obj.
send(obj, msg, args)Call the method msg on obj.
_send(cls, obj, msg, args)Manually call the method msg on class cls, using obj as the instance.
Note that there is no guarantee that the method called is compatible with obj.
getsuper(cls)Get the superclass of the class cls.
getclass(obj)Get the class of obj.
new(class, args)Create an instance of a class.
class(super, methods)Define a class that extends super.
The methods value should be a hashmap of functions.
NoSuchMethodErrorError raised when an unrecognized message is sent to an object.
Utilities for manipulating filesystem paths.
ext(path)Get the extension of path, without the ‘.’.
basename(path)Get the portion of path after the last ‘/’.
If there is no ‘/’ in path, the same string is returned.
dirname(path)Return the portion of path that is before the last ‘/’.
If there is no ‘/’ in path, ‘.’ is returned.
join(a, b)Join the paths a and b with a ‘/’.
Primitive regular expressions.
match(nfa, text)Match some text against an NFA generated by compile.
compile(exp)Compile a regular expression string into an NFA.