The Gleam Standard Library
The animator's Gleam code uses the types and functions from Gleam's standard
library (gleam_stdlib) listed below. A few
others aren't listed because only parser.gleam or the grader's decoding uses
them. Each description is the first paragraph of that type or function's
documentation; follow its link for the rest, including examples.
These are separate from the built-in functions that a draw function can
call, which are listed in A Subset of Gleam.
gleam/dict
- type
Dict: A dictionary of keys and values. dict.each: Calls a function for each key and value in a dict, discarding the return value.dict.from_list: Converts a list of 2-element tuples#(key, value)to a dict.dict.get: Fetches a value from a dict for a given key.dict.keys: Gets a list of all keys in a given dict.dict.merge: Creates a new dict from a pair of given dicts by combining their entries.dict.new: Creates a fresh dict that contains no values.
gleam/float
float.random: Generates a random float between the given zero (inclusive) and one (exclusive).float.truncate: Returns the value as anInt, truncating all decimal digits.
gleam/int
int.absolute_value: Returns the absolute value of the input.int.max: Compares two ints, returning the larger of the two.int.to_float: Takes an int and returns its value as a float.int.to_string: Prints a given int to a string.
gleam/io
io.println: Writes a string to standard output (stdout), appending a newline to the end.
gleam/list
list.append: Joins one list onto the end of another.list.count: Counts the number of elements in a given list satisfying a given predicate.list.filter: Returns a new list containing only the elements from the first list for which the given functions returnsTrue.list.find: Finds the first element in a given list for which the given function returnsTrue.list.find_map: Finds the first element in a given list for which the given function returnsOk(new_value), then returns the wrappednew_value.list.flatten: Joins a list of lists into a single list.list.fold: Reduces a list of elements into a single value by calling a given function on each element, going from left to right.list.key_find: Given a list of 2-element tuples, finds the first tuple that has a given key as the first element and returns the second element.list.length: Counts the number of elements in a given list.list.map: Returns a new list containing the results of applying the supplied function to each element.list.reverse: Creates a new list from a given list containing the same elements but in the opposite order.list.try_fold: A variant of fold that might fail.list.try_map: Takes a function that returns aResultand applies it to each element in a given list in turn.list.zip: Takes two lists and returns a single list of 2-element tuples.
gleam/option
- type
Option(with constructorsNoneandSome):Optionrepresents a value that may be present or not.Somemeans the value is present,Nonemeans the value is not.
gleam/result
result.map: Updates a value held within theOkof a result by calling a given function on it.result.map_error: Updates a value held within theErrorof a result by calling a given function on it.result.replace_error: Replace the error within a resultresult.try: "Updates" anOkresult by passing its value to a function that yields a result, and returning the yielded result. (This may "replace" theOkwith anError.)result.unwrap: Extracts theOkvalue from a result, returning a default value if the result is anError.
gleam/string
string.inspect: Returns aStringrepresentation of a term in Gleam syntax.string.join: Joins manyStrings together with a given separator.string.length: Gets the number of grapheme clusters in a givenString.string.pad_end: Pads the end of aStringuntil it has a given length.string.replace: Creates a newStringby replacing all occurrences of a given substring.string.split: Creates a list ofStrings by splitting a given string on a given substring.string.starts_with: Checks whether the firstStringstarts with the second one.