Home / Docs / Standard library / Prelude
contains
Release v0.4.0Edition 0.1 and later
A function of the prelude, in scope in every module. Edition 0.1 and later.
Edition 0.1
una
pub contains[T](xs: List[T], item: T) -> BoolCompares structurally; in edition 0.2 and later, over any type with Eq (spec/14 §1, spec/20 §6).
Edition 0.2 and later
una
pub contains[T: Eq](xs: List[T], item: T) -> BoolCompares structurally; in edition 0.2 and later, over any type with Eq (spec/14 §1, spec/20 §6).
In editions 0.2, 0.3, 0.4, 0.5. In edition 0.1: contains[T](xs: List[T], item: T) -> Bool: no Eq constraint on T.
Parameters
xs: the listitem: the value to look for
Returns
Bool: true when an element of xs equals item, compared structurally.
Use instead
first_whereto find the element itself, by a condition
Example
src/shop.una
module shop
--- Whether a cart holds an item.
pub main() -> Unit
uses @console: Console[print]
=
let cart = ["lamp", "desk"]
let desk = cart.contains(item: "desk")
@console.print("desk: {desk}")
let chair = cart.contains(item: "chair")
@console.print("chair: {chair}")una run . prints:
Output
desk: true
chair: 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.