Home / Docs / Standard library / Prelude

ends_with

Release v0.4.0Edition 0.2 and later

A function of the prelude, in scope in every module. Edition 0.2 and later.

una
pub ends_with(t: Text, suffix: Text) -> Bool

Whether t ends with suffix (spec/22 §2).

Parameters

Returns

Bool: true when the last scalar values of t are those of suffix.

See also

starts_with, contains_text

Cost

Time O(m) (ADR 0070), where:

Example

src/shop.unauna
module shop

--- Whether an uploaded invoice is a PDF.
pub main() -> Unit
  uses @console: Console[print]
=
  let pdf = ends_with("invoice-2026.pdf", suffix: ".pdf")
  @console.print("invoice-2026.pdf: {pdf}")
  let text = ends_with("invoice-2026.txt", suffix: ".pdf")
  @console.print("invoice-2026.txt: {text}")

una run . prints:

Output
invoice-2026.pdf: true
invoice-2026.txt: 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.