Wolfram Research

Function Repository Resource:

AllSameAs

Source Notebook

Check if all elements of a list are the same as a value

Contributed by: Taliesin Beynon

ResourceFunction["AllSameAs"][list,val]

yields True if all elements of list are identical to val.

Details and Options

Elements are considered identical if SameQ gives True with val.

Examples

Basic Examples

Check if all elements match a value:

In[1]:=
ResourceFunction["AllSameAs"][{1, 1, 1}, 1]
Out[1]=

If any values do not match, AllSameAs gives False:

In[2]:=
ResourceFunction["AllSameAs"][{1, 2, 1}, 1]
Out[2]=

Properties and Relations

Patterns are not supported:

In[3]:=
ResourceFunction["AllSameAs"][{1, 2, 3}, _Integer]
Out[3]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information