gtin/internal/utils

Internal utility functions for the GTIN library. These functions are not part of the public API.

Values

pub fn last_digit(digits: List(Int)) -> Int

Extract the last digit from a list of integers.

Returns the last element if the list is non-empty, otherwise returns 0.

Examples

last_digit([1, 2, 3])
// -> 3

last_digit([])
// -> 0
pub fn parse_digit(char: String) -> Result(Int, Nil)

Parse a single character to an integer digit.

Returns Ok(digit) if the character is a digit (0-9), otherwise returns Error.

Examples

parse_digit("5")
// -> Ok(5)

parse_digit("a")
// -> Error(InvalidCharacters)
Search Document