lenient_parse

Package Version Hex Docs

A Gleam library providing lenient parsing functions for converting strings to float and integer values. This package offers more flexible parsing than the standard Gleam functions, similar to Python’s built-in float() and int() functions.

Installation

gleam add lenient_parse
import lenient_parse
import gleam/io

pub fn main() {
  "1" |> lenient_parse.to_float |> io.debug
  // Ok(1.0)

  "1.001" |> lenient_parse.to_float |> io.debug
  // Ok(1.001)

  "+123.321" |> lenient_parse.to_float |> io.debug
  // Ok(123.321)

  "-123.321" |> lenient_parse.to_float |> io.debug
  // Ok(-123.321)

  "1_000_000.0" |> lenient_parse.to_float |> io.debug
  // Ok(1000000.0)

  "123" |> lenient_parse.to_int |> io.debug
  // Ok(123)

  "+123" |> lenient_parse.to_int |> io.debug
  // Ok(123)

  "-123" |> lenient_parse.to_int |> io.debug
  // Ok(-123)

  "1_000_000" |> lenient_parse.to_int |> io.debug
  // Ok(1000000)
}
Search Document