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) -> BoolWhether t ends with suffix (spec/22 §2).
Parameters
t: the textsuffix: the texttmay end with
Returns
Bool: true when the last scalar values of t are those of suffix.
See also
Cost
Time O(m) (ADR 0070), where:
m: the length ofsuffixin UTF-8 bytes
Example
src/shop.una
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: 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.