Home / Docs / Standard library / Prelude
append
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 append[T](xs: List[T], item: T) -> List[T]
ensures result.len == xs.len + 1xs with item added after its last element (spec/14 §1).
Parameters
xs: the listitem: the element to add
Returns
List[T]: xs with item after its last element; one element longer than xs.
See also
set (edition 0.2 on)
Cost
Time amortized O(1) append, O(n) copy when the list is shared (ADR 0107), where:
n: the length ofxs
Example
src/shop.una
module shop
--- A cart with one more item.
pub main() -> Unit
uses @console: Console[print]
=
let cart = ["lamp"].append(item: "chair")
@console.print(join(cart, separator: ", "))
@console.print("{cart.len} items")una run . prints:
Output
lamp, chair
2 itemsSpecification
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.