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 an Int, truncating all decimal digits.

gleam/int

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 returns True.
  • list.find: Finds the first element in a given list for which the given function returns True.
  • list.find_map: Finds the first element in a given list for which the given function returns Ok(new_value), then returns the wrapped new_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 a Result and 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 constructors None and Some): Option represents a value that may be present or not. Some means the value is present, None means the value is not.

gleam/result

  • result.map: Updates a value held within the Ok of a result by calling a given function on it.
  • result.map_error: Updates a value held within the Error of a result by calling a given function on it.
  • result.replace_error: Replace the error within a result
  • result.try: "Updates" an Ok result by passing its value to a function that yields a result, and returning the yielded result. (This may "replace" the Ok with an Error.)
  • result.unwrap: Extracts the Ok value from a result, returning a default value if the result is an Error.

gleam/string

  • string.inspect: Returns a String representation of a term in Gleam syntax.
  • string.join: Joins many Strings together with a given separator.
  • string.length: Gets the number of grapheme clusters in a given String.
  • string.pad_end: Pads the end of a String until it has a given length.
  • string.replace: Creates a new String by replacing all occurrences of a given substring.
  • string.split: Creates a list of Strings by splitting a given string on a given substring.
  • string.starts_with: Checks whether the first String starts with the second one.

Back to Top

Accessibility Nondiscrimination

Copyright ©2026, Regents of the University of California and respective authors.

This site is built following the Berkeley Class Site template, which is generously based on the Just the Class, and Just the Docs templates.

View all course offerings