Function Repository Resource:

SuccessfulQ

Source Notebook

Test if an expression is considered successful

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["SuccessfulQ"][expr]

gives False if expr is a failure or missing value and True otherwise.

Details

ResourceFunction["SuccessfulQ"] considers expr to be successful as long as expr does not have any of the following forms:
ResourceFunction["SuccessfulQ"] has the attribute SequenceHold.

Examples

Basic Examples (1) 

Test if an expression is successful:

In[1]:=
ResourceFunction["SuccessfulQ"][x]
Out[1]=
In[2]:=
ResourceFunction["SuccessfulQ"][1 + 1]
Out[2]=
In[3]:=
ResourceFunction["SuccessfulQ"][$Failed]
Out[3]=
In[4]:=
ResourceFunction["SuccessfulQ"][Missing["NotFound"]]
Out[4]=

Scope (1) 

SuccessfulQ gives False for any expression that would be considered a failure by Confirm:

In[5]:=
ResourceFunction["SuccessfulQ"][Failure["Tag", <||>]]
Out[5]=
In[6]:=
ResourceFunction["SuccessfulQ"][Missing["NotFound"]]
Out[6]=
In[7]:=
ResourceFunction["SuccessfulQ"][$Canceled]
Out[7]=
In[8]:=
ResourceFunction["SuccessfulQ"][$Aborted]
Out[8]=

Properties and Relations (2) 

SuccessfulQ has the attribute SequenceHold:

In[9]:=
ResourceFunction["SuccessfulQ"][Sequence[a, b]]
Out[9]=
In[10]:=
ResourceFunction["SuccessfulQ"][Sequence[$Failed]]
Out[10]=
In[11]:=
ResourceFunction["SuccessfulQ"][Evaluate[Sequence[$Failed]]]
Out[11]=

Confirm[expr] is effectively equivalent to ConfirmBy[expr,SuccessfulQ]:

In[12]:=
Enclose[f[x, Confirm[y], z]]
Out[12]=
In[13]:=
Enclose[f[x, ConfirmBy[y, ResourceFunction["SuccessfulQ"]], z]]
Out[13]=
In[14]:=
Enclose[f[x, Confirm[$Failed], z]]
Out[14]=
In[15]:=
Enclose[f[x, ConfirmBy[$Failed, ResourceFunction["SuccessfulQ"]], z]]
Out[15]=

Possible Issues (1) 

SuccessfulQ expects a single argument:

In[16]:=
ResourceFunction["SuccessfulQ"][a, b]
Out[16]=

Version History

  • 1.0.0 – 23 May 2022

Related Resources

License Information