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.
generator
The interface for a documentation generator.
module
Create an object to document members of a module.
A growable array.
to_iter(list)
Create an iterator over the arraylist.
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_index(list, func)
Get the first element that satisfies the predicate func
, or null if none exists.
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
.
collector
A 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.
iter(list)
Create an iterator over arraylist list
.
from_array(len, array)
Create a new arraylist from array
. The len
argument should be the length
of array
.
Functions for working with arrays.
slice(array, start, end)
Returns a slice of array
starting at index start
and ending at index end
.
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 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.
collector
A collector for converting an iterator into an array.
iter(array)
Create an iterator from array array
.
length(array)
Get the length of array array
.
new(len)
Create a new array of length len
.
Lazy iterators.
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(it, init, reducer)
Reduce the iterator, using init
as the initial value of the accumulator.
fold1(it, reducer)
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.
collector
An struct defining the required functions to convert an iterator into an arbitrary collection.
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
.
collector
A collector for converting an iterator of entries into an assoclist.
iter(list)
Create an iterator over the entries of list
.
length
Check the number of items in the list.
new
Create an empty assoclist.
A compact byte array type.
collector
A collector for converting an iterator into byte array.
length(bytes)
Get the length of bytes
.
set(bytes, i, val)
Set the i
th value in bytes
to val
.
get(bytes, i)
Get the i
th 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.
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.
Math functions.
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
.
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 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
.
Functions for working with strings.
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.
collector
A collector to convert an iterator of characters or strings into a string.
iter(str)
Create an iterator over the characters in str
.
char_at(string, idx)
Get the idx
th character of 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)
Panics if cond
is not truthy.
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.
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)
Call from_entries_with_hash_function
with the default hash function and entries
.
from_entries_with_hash_function(hash, entries)
Create a new hashmap with hash
as its hash function, and populate it from
the iterator of key-value pairs entries
.
make(init)
Call make_with_hash_function
with the default hash function and init
.
make_with_hash_function(hash, init)
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)
Count the number of values in map
.
iter(map)
Get an iterator over the key-value pairs 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.
with_hash_function(func)
Create a new hash map that uses func
as its hash function.
set_hash_function(map, func)
Set the hash function used by map
to func
.
new()
Create a hashmap in the default configuration.
with_capacity(n)
Create a new hashmap with n
buckets.
collector(hash_fn=...)
Create a collector for converting an iterator of entries into a hashmap.
A result type. Probably rendered obsolete by panicking.
map_error(result, fn)
Return a new result where the value has been processed by fn
if the result
was unsuccessful.
map(result, fn)
Return a new result where the value has been processed by fn
if the result
was successful.
data(result)
Get the value from result
.
code(result)
Get the error code from result
.
is_error(result)
Check if result
was unsuccessful.
is_ok(result)
Check if result
was successful.
error(code, value)
Create a failed result with error code code
and data value
.
ok(value)
Create a successful result containing value
.
ERROR
A sentinel value representing an unsuccessful result.
OK
A sentinel value representing a successful result.
A partial implementation of a JSON parser.
parse(input)
Parse the string input
as JSON.
The returned value is a result
, for historical reasons (lol). See the result
module for more information.
E_INVALID_JSON
An error returned when the input string is not able to be parsed.
E_UNEXPECTED_TOKEN
An error returned when an unexpected token is encountered.
A linked list implementation.
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.
collector
A 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
.
append(list, value)
Add a value to the end of the list.
Like length
, this function is O(n).
prepend(list, value)
Add a value to the front of the list.
This function is O(1) (i.e. takes the same time regardless of the length of the list).
length(list)
Get the length of the list.
Note that this is O(n) (i.e. requires traversing the entire list).
iter(list)
Create an iterator over list
.
new()
Create a new, empty linked list.
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.
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.