Skip to content

FirstCase

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

FirstCase[expr, patt]

Gives the first element of expr matching patt, or Missing["NotFound"]. FirstCase[expr, patt, default] uses default. Over an association, matches values and returns the first match.

Examples (3)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (3)

In[1]:= SelectFirst[{1, 3, 4, 5, 6}, EvenQ]
Out[1]= 4

In[2]:= FirstCase[{1, 2, 3, 4}, _?EvenQ]
Out[2]= 2

In[3]:= SelectFirst[{1, 3, 5}, EvenQ, None]
Out[3]= None

Implementation notes

Attributes: Protected.

References

See also: SelectFirst