Home / Docs / Standard library / Prelude

starts_with

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 starts_with(t: Text, prefix: Text) -> Bool

Whether t starts with prefix, comparing Unicode scalar values (spec/14 §1).

Parameters

Returns

Bool: true when the first scalar values of t are those of prefix.

See also

ends_with (edition 0.2 on), contains_text (edition 0.2 on)

Example

src/shop.unauna
module shop

--- Whether an SKU belongs to the lamp range.
pub main() -> Unit
  uses @console: Console[print]
=
  let lamp = starts_with("LAMP-01", prefix: "LAMP")
  @console.print("LAMP-01: {lamp}")
  let lower = starts_with("lamp-01", prefix: "LAMP")
  @console.print("lamp-01: {lower}")

una run . prints:

Output
LAMP-01: true
lamp-01: 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.