qol_gleam/qol_int

Values

pub fn digits(x: Int, base: Int) -> Result(List(Int), Nil)

Splits an integer into its digit representation in the specified base. Returns an error if the base is less than 2.

Examples

digits(234, 10)
// -> Ok([2,3,4])
digits(234, 1)
// -> Error(Nil)

Origin

This function was from the stdlib and was deprecated since v0.62.0 as due to confusion with the name and lack of common use case.

pub fn undigits(
  numbers: List(Int),
  base: Int,
) -> Result(Int, Nil)

Joins a list of digits into a single value. Returns an error if the base is less than 2 or if the list contains a digit greater than or equal to the specified base.

Examples

undigits([2,3,4], 10)
// -> Ok(234)
undigits([2,3,4], 1)
// -> Error(Nil)
undigits([2,3,4], 2)
// -> Error(Nil)

Origin

This function was from the stdlib and was deprecated since v0.62.0 as due to confusion with the name and lack of common use case.

Search Document