From 94ce7dceedc91ac743bd9ee068dc9d4fa91a7dd1 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 10 Oct 2024 12:29:03 -0400 Subject: [PATCH] Update doc comment --- src/lenient_parse.gleam | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lenient_parse.gleam b/src/lenient_parse.gleam index ccd3e58..1a0c7a0 100644 --- a/src/lenient_parse.gleam +++ b/src/lenient_parse.gleam @@ -6,19 +6,21 @@ import gleam/string /// Converts a string to a float using a more lenient parsing method than gleam's `float.parse()`. It behaves similarly to Python's `float()` built-in function. /// -/// It attempts to parse the input string in the following order: -/// 1. As a standard float -/// 2. As an integer (which is then converted to a float) -/// 3. As a float with leading or trailing decimal point -/// /// ## Examples /// /// ```gleam -/// lenient_parse.to_float("3.14") // -> Ok(3.14) -/// lenient_parse.to_float("42") // -> Ok(42.0) -/// lenient_parse.to_float(".5") // -> Ok(0.5) -/// lenient_parse.to_float("2.") // -> Ok(2.0) -/// lenient_parse.to_float("dog") // -> Error(Nil) +/// lenient_parse.to_float("1.001") // -> Ok(1.001) +/// lenient_parse.to_float("1") // -> Ok(1.0) +/// lenient_parse.to_float("1.") // -> Ok(1.0) +/// lenient_parse.to_float("1.0") // -> Ok(1.0) +/// lenient_parse.to_float(".1") // -> Ok(0.1) +/// lenient_parse.to_float("0.1") // -> Ok(0.1) +/// lenient_parse.to_float("+123.321") // -> Ok(123.321) +/// lenient_parse.to_float("-123.321") // -> Ok(-123.321) +/// lenient_parse.to_float(" 1.0 ") // -> Ok(1.0) +/// lenient_parse.to_float(" ") // -> Error(Nil) +/// lenient_parse.to_float("") // -> Error(Nil) +/// lenient_parse.to_float("abc") // -> Error(Nil) /// ``` pub fn to_float(text: String) -> Result(Float, Nil) { let text = text |> string.trim @@ -33,7 +35,6 @@ pub fn to_float(text: String) -> Result(Float, Nil) { _, _ -> Error(Nil) } } -// TODO: Update doc comment with rules and examples // TODO: README // TODO: GitHub repo description // TODO: gleam.toml