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) -> Bool

Compares 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) -> Bool

Compares 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

Returns

Bool: true when an element of xs equals item, compared structurally.

Use instead

Example

src/shop.unauna
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: 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.