Home / Docs / Standard library / Prelude
is_digits
Release v0.4.0Edition 0.1 and later
A function of the prelude, in scope in every module. Edition 0.1 and later.
una
pub is_digits(t: Text) -> BoolWhether every character of t is an ASCII digit, so it holds of the empty text (spec/14 §1).
Parameters
t: the text
Returns
Bool: true when every character of t is an ASCII digit, so also for the empty text.
Use instead
parse_int(edition 0.2 on) to read the number the digits write, with a reason when there is none
See also
Example
src/shop.una
module shop
--- Whether a typed article number is one: all digits, and not empty, since the empty text
--- is all digits too.
article(raw: Text) -> Text
=
let digits = raw.is_digits()
let valid = raw.len > 0 and digits
"'{raw}': all digits {digits}, an article number {valid}"
pub main() -> Unit
uses @console: Console[print]
=
@console.print(article("12345"))
@console.print(article("12a45"))
@console.print(article(""))una run . prints:
Output
'12345': all digits true, an article number true
'12a45': all digits false, an article number false
'': all digits true, an article number falseSpecification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.