Qu

find

Builtin index · Core maths

find(mask) or find(collection, fnName)

Input: mask · Output: no output

What it is

One argument: identical to where(mask) — the indices where a boolean mask is true, as a Vec. Two arguments: collection (any indexable/iterable value) and fnName (a Str naming an already-defined one-argument predicate function); returns the first element of collection for which that predicate is truthy.

Overloads

mask can be boolean, Vec, Str, or Mat.

2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.

CodeInputOutputDescription
result = find(mask)
mask boolean, Vec, Str, or Matnot documented yet
result boolean, Vec, or Mat
Identical to where(mask) — the indices where a boolean Vec/Mat is true.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

mask = [true, false, true]
print(find(mask))                 # [0, 2] -- same as where(mask)


is_even(n) := n mod 2 == 0
xs = [1, 3, 4, 5, 6]
print(find(xs, "is_even"))        # 4 -- first element, not an index

output
[0, 2]
4

from core-math

CodeInputOutputDescription
result = find(collection, fnName)
collection Strcollection (any indexable/iterable value) and fnName (a Str naming an already-defined one-argument predicate) — returns the *first element* of collection for which that predicate is truthy, not an index.
fnName StrTwo arguments: collection (any indexable/iterable value) and fnName (a Str naming an already-defined one-argument predicate function).
collection —any indexable/iterable value
fnName Stra Str naming an already-defined one-argument predicate
collection (any indexable/iterable value) and fnName (a Str naming an already-defined one-argument predicate) — returns the *first element* of collection for which that predicate is truthy, not an index.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

is_even(n) := n mod 2 == 0
xs = [1, 3, 4, 5, 6]
print(find(xs, "is_even"))   # 4 -- first element for which is_even is true

output
4

from core-math

mask = [true, false, true]
print(find(mask))                 # [0, 2] -- same as where(mask)


is_even(n) := n mod 2 == 0
xs = [1, 3, 4, 5, 6]
print(find(xs, "is_even"))        # 4 -- first element, not an index

output
[0, 2]
4

from core-math

How it works

selection: where(cond) -> indices where the mask is true. find(collection, fnName) — predicate search (§ collections, 2026-08-24), a *different* 2-argument form distinguished by arity (a mask and a (collection, function-name) pair can't be confused): returns the first element for which fnName is truthy, via find_predicate. where keeps its original 1-argument-only meaning — where(xs, "fn") is a clear error rather than silently reinterpreted, since where never meant "search a collection".

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.