SelectFirst

SelectFirst[{e1,e2,},crit]
gives the first for which is True, or Missing["NotFound"] if none is found.

SelectFirst[{e1,e2,},crit,default]
gives default if there is no such that is True.

SelectFirst[crit]
represents an operator form of SelectFirst that can be applied to an expression.

DetailsDetails

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Select the first element that is even:

In[1]:=
Click for copyable input
Out[1]=

Use a pure function to test elements:

In[1]:=
Click for copyable input
Out[1]=

Give the default x when no even numbers are found:

In[1]:=
Click for copyable input
Out[1]=

SelectFirst operates on values in an Association:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2014
(10.0)