dataprep/parse
Values
pub fn float(
raw: String,
on_error: fn(String) -> e,
) -> validated.Validated(Float, e)
Parse a string as Float. On failure, call on_error with the
original string to produce the error value.
Accepts every shape gleam/float.parse accepts (e.g. "3.14",
"-0.5") and additionally accepts:
- integer literals —
"5"parses as5.0(asymmetric strictness betweenparse.intandparse.floatwas a UX trap when the raw input is a user-typed numeric value). - scientific notation —
"1e3","1.5e-2","5E3"are all accepted; the exponent must itself be a valid integer.
Example: parse.float(raw, fn(s) { NotAFloat(s) })
pub fn int(
raw: String,
on_error: fn(String) -> e,
) -> validated.Validated(Int, e)
Parse a string as Int. On failure, call on_error with the
original string to produce the error value.
Example: parse.int(raw, fn(s) { NotAnInteger(s) })