contains
Builtin index · Collections & strings
result = contains(collection, value)
Input: collection, value · Output: result
What it is
collection is a Vec or List; value is any comparable element.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = contains(collection, value) | collection Vec or Listcollection is a Vec or List.value —value is any comparable element. | result bool | Returns a bool: membership test via structural equality. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
ys = [3, 1, 4, 1, 5]
print(contains(ys, 4)) # true
print(indexof(ys, 4)) # 2
print(cumsum(ys)) # [3, 4, 8, 9, 14]
print(numel(ys)) # 5
output
true 2 [3, 4, 8, 9, 14] 5
from collections-strings
s = " Measurement Lane "
print("[{trim(s)}]") # [Measurement Lane]
print(upper(trim(s))) # MEASUREMENT LANE
print(contains(s, "Lane")) # true
print(replace(s, "Lane", "Window"))
output
[Measurement Lane] MEASUREMENT LANE true Measurement Window
from agent-guide
figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#ff0000")
savefig(tmp_svg)
print(contains(read_all_text(tmp_svg), "opacity=\"0.18\"")) # true
from agent-guide
How it works
contains(collection, value) — boolean membership test, over either a numeric Vec or a heterogeneous List (structural equality via values_equal, not the == operator, which doesn't compare Strs today — a pre-existing, separate gap).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.