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) -> Bool

Whether every character of t is an ASCII digit, so it holds of the empty text (spec/14 §1).

Parameters

Returns

Bool: true when every character of t is an ASCII digit, so also for the empty text.

Use instead

See also

to_int

Example

src/shop.unauna
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 false

Specification

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.